Token-checked LLM call
If the prompt is over the budget, the pipeline stops and the model never sees a prompt that only half fits.
Count the tokens in a prompt and stop the pipeline before the LLM call if the prompt is over a budget.
Pipeline
cat prompt.txt \
| vrk tok --check 4000 \
| vrk prompt --system "Summarise this."
The problem
LLMs have context windows. When your input exceeds the limit, the API either truncates silently or returns an error after you’ve already waited for the response and spent tokens on the request. In a pipeline, this is worse - downstream steps process garbage output without knowing the input was incomplete.
This bug is expensive because it looks like success. The API returns 200, the model responds, but the answer is based on a truncated document.
How the pipeline works
vrk tok --check 4000 reads stdin, counts tokens, and makes a decision. If the count is 4000 or under, it passes the text through unchanged to stdout. If over, it exits 1 with empty stdout. vrk prompt gets no input, exits 1 with prompt: empty prompt, nothing sent, and no request reaches the API.
The pipeline sends no request and returns a clear exit code, so you never get a truncated answer.
When it fails
When the token count exceeds the budget, vrk tok exits 1 and the pipeline stops immediately. The exit code propagates - your shell script, CI job, or agent sees a non-zero exit and knows the step failed. You can catch this and handle it (chunk the document, summarize a section, or report the error) instead of processing bad output.
Variations
Gate before a batch job to skip oversized documents:
for f in docs/*.md; do
cat "$f" | vrk tok --check 8000 | vrk prompt --system "Extract key points" >> output.txt 2>/dev/null
done
Use --json for structured error reporting:
cat prompt.txt | vrk tok --check 4000 --json
# Over budget: {"code":1,"error":"6201 tokens exceeds limit of 4000","limit":4000,"tokens":6201}