prompt-budget-check v1.0.0

Crystal command line tool: estimates the token size of each prompt from character counts and a chars-per-token ratio you set, and flags prompts near or over your budget.

prompt-budget-check

Crystal command line tool and library. Give it a CSV of prompts and it estimates the token size of each one and compares it with a budget. Estimated tokens = ceil(characters / chars-per-token), where characters is the count of Unicode characters of the trimmed text. The chars-per-token ratio (default 4), the token budget --limit (default 1000) and the warning share --warn-at (default 80, a percent of the limit) are all set by you: the numbers are rough estimates, real tokenizers differ, and no model or vendor is assumed. Status per prompt: over when the estimate is above the limit, warn when it is at or above the warn share of the limit, otherwise ok. Share of limit is shown with 1 decimal. The summary gives prompts, ok, warn, over, total estimated tokens and the longest prompt id (by estimated tokens, ties to the alphabetically first id).

Part of the OneGTMLab free GTM tools. Background on the idea: prompt engineering.

Install

shards build   # then ./bin/prompt-budget-check

Use

Input: CSV with the columns prompt_id and text (any order, header case does not matter). A text cell may be double quoted and then may contain commas, line breaks and "" for a quote mark. Options: --chars-per-token (a number above 0), --limit (a whole number above 0), --warn-at (above 0 and up to 100), each as --name value or --name=value. The example below sets a small limit of 50 tokens only so that all three statuses show up on a small sample. A missing column, an empty text cell (the message names the row, the header counts as row 1), a bad option value or a missing file stops the run with a message and exit 1.

$ bin/prompt-budget-check sample.csv --chars-per-token 4 --limit 50
prompt_id  characters  words  est tokens  share of limit  status
p1         48          8      12          24.0%           ok
p2         72          12     18          36.0%           ok
p3         53          10     14          28.0%           ok
p4         181         36     46          92.0%           warn
p5         291         55     73          146.0%          over

prompts: 5
ok: 3
warn: 1
over: 1
total estimated tokens: 163
longest prompt: p5
settings: 4 chars per token, limit 50 tokens, warn at 80% of the limit

Test

crystal spec

Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.

Repository

prompt-budget-check

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 0
  • about 1 hour ago
  • November 29, 2026
License

MIT License

Links
Synced at

Sun, 29 Nov 2026 02:03:47 GMT

Languages