New Tool Radar

AI Concepts

How to Count Tokens Before Sending a Prompt So It Fits the Context Window

Count the prompt tokens first, so a long prompt never gets cut off mid-way.

Schematic with three numbered boxes: count prompt tokens, add reply room, compare with the window.

Every model has a context window measured in tokens, and a prompt that is too long gets truncated or rejected. Counting tokens before you send takes a minute and saves a failed run. Ollama 0.10.0 made ollama ps show the context length of loaded models, so you can see the limit before you start.

Checked on 2026-11-29. We did not run any tool for this guide. Every result below is an expected result, marked UNTESTED, for you to confirm on your own files.

Prerequisites

  • The prompt text you plan to send
  • The model context window size
  • A token counter, or the estimate that one token is about four characters of English text

Steps

1. Count the prompt tokens

Paste the prompt into a token counter and write the number down. Include any documents you attach.

Expected result: A token count exists for the full prompt with attachments.

2. Add room for the reply

Add the tokens you expect back, for example 1,000 for a short answer. The total must stay under the window.

Expected result: A total with reply room is written down.

3. Compare with the window

If the total is under the window, send it. If it is over, shorten the prompt or split the documents.

Expected result: The prompt is sent, or a shortening plan exists.

4. Check the reply is complete

Read the reply to the end. A reply that stops mid-sentence means the window ran out.

Expected result: The reply is marked complete or cut off, with the cause noted.

Worked example

A practice prompt with a short report attached was counted before sending to a 32,768 token window.

Part Tokens Running total
Instruction 120 120
Report text 8400 8520
Reply room 1000 9520

Expected result: The prompt totals 9,520 tokens with reply room, well under the 32,768 window, so it is sent as written (UNTESTED – confirm it yourself.)

Verdict table

Check Expected result Pass?
Count the prompt tokens A token count exists for the full prompt with attachments. –
Add room for the reply A total with reply room is written down. –
Compare with the window The prompt is sent, or a shortening plan exists. –
Check the reply is complete The reply is marked complete or cut off, with the cause noted. –

Limits

  • The four-characters-per-token estimate is rough; a real counter is better for long prompts.
  • Different models count tokens differently, so a count for one model may not fit another.

Sources

See all