long-context-truncation-check · EN · 2026-10-19

Silent Truncation at the Context Edge: Detecting Where Each Backend Stops Reading Your Long Prompt

A practical guide to detecting where each model backend actually stops reading a long prompt, using a needle-in-haystack probe script run through a multi-model API aggregator, and how to interpret the results.

Why advertised context limits are not the whole story

Most model providers publish a context window, but the number you see in a model card is an upper bound, not a promise about behaviour near that bound. Several things can make the effective context shorter than the advertised one:

  • Serving configuration. A backend may run with a smaller max sequence length than the model was trained for.
  • Silent truncation policies. Some gateways drop tokens from the middle or the start rather than erroring when a request is too long.
  • Per-request output reservation. If output tokens are reserved out of the same window, the usable input portion shrinks.
  • Routing differences. On an aggregator, the same model name may be served by more than one upstream, each with its own limits.

When truncation is silent, you get a plausible but incomplete answer instead of an error. That is the failure mode worth measuring.

The needle-in-haystack idea

A needle-in-haystack probe places one uniquely identifiable fact (the needle) at a known position inside a long body of filler text (the haystack) and asks the model to return it. By sweeping two variables — total input length and needle position — you can see where retrieval starts to fail.

Two distinct signals matter:

  • Position sensitivity. If the needle is found at the start but not near the end, you are hitting a truncation edge.
  • Length sensitivity. If accuracy collapses beyond a certain total length regardless of needle position, you have found the effective ceiling for that backend.

The goal is not a benchmark score. It is a per-model map of where reading stops.

Designing the probe

Keep the probe simple and deterministic so results are easy to trust.

  • Needle: a short random token (for example a made-up identifier) that cannot be guessed or paraphrased.
  • Haystack: neutral filler text in the same language and style, long enough to reach your target lengths.
  • Positions: at minimum, place the needle near the start, in the middle, and near the end.
  • Lengths: choose a ladder of total input sizes that brackets the advertised limit from well below to at or slightly above it.
  • Instruction: ask the model to repeat the identifier verbatim, nothing else.
  • Scoring: exact match only. A model that describes the needle has not retrieved it.

Run each combination more than once, because sampling and backend routing can both add variance.

A sketch of the script

Conceptually the loop is:

  1. Build the haystack at the target token or character length.
  2. Insert the needle at the target relative position.
  3. Send the request through your aggregator endpoint with your single API key, specifying the model under test.
  4. Record whether the response contains the exact needle.
  5. Append one row to a results table: model, total length, position, hit or miss.

Because the aggregator exposes many models behind one key, you can run the same probe matrix across Claude, GPT, DeepSeek, Qwen, GLM, Kimi and others without managing separate credentials or billing relationships. That uniformity is the main practical advantage: the script stays identical, only the model field changes.

Practical details worth handling:

  • Token counting. Approximate token counts are fine, but keep the estimate method consistent across models so the comparison is fair.
  • Timeouts and retries. Long prompts are slow. Treat a timeout as a separate outcome from a miss.
  • Error capture. Distinguish a clean API error (explicit over-limit rejection) from a 200 response with a wrong or missing answer (silent truncation).
  • Cost awareness. Every probe is a billed call. On this platform you pay the official price × 1.3, so a large sweep across many models is real spend — keep the matrix tight and reuse results.

Reading the results

Plot hits and misses by length for each model. Typical patterns:

  • Clean ceiling. Hits until a length, then explicit errors or consistent misses everywhere. The effective limit is close to the advertised one.
  • Early truncation. Misses appear well before the advertised limit, especially for needles near the end. Suggests a smaller served window or middle-dropping behaviour.
  • Position-only failure. Long inputs work when the needle is early but fail when it is late. This is the classic silent-truncation signature.
  • Uniform degradation. Accuracy falls with length but not position. That is an attention/quality effect rather than a hard cut.

Record the lowest length at which a consistent miss appears as your working effective context for that backend, and note the position pattern alongside it.

Turning the probe into a habit

  • Re-run after changes. Upstream routing and serving configs change without announcement. Re-probe periodically, or whenever a long-prompt workflow starts behaving oddly.
  • Keep a per-model note. Store the measured effective context next to your prompts so you can size inputs deliberately rather than hoping.
  • Design defensively. Put critical instructions and key facts near the start of long prompts, restate the single most important constraint at the end, and split genuinely long tasks into stages.
  • Prefer explicit failure. Where a backend returns an over-limit error, respect it; where it silently truncates, keep your own input below the measured edge.

Cost note for contributors

The probe sweep is a normal API workload, billed at official price × 1.3. If you publish your measured results as a model-evaluation dataset or tooling, the platform's contributor credit (official price × 1.1, or × 1.2 for premium contributions, paid in USDC) applies to qualifying contributions — so careful, well-documented probe results can partly offset the cost of producing them.

Summary

Advertised context windows are ceilings, not guarantees. A small needle-in-haystack probe, run uniformly across models through one aggregator key, gives you a concrete per-backend map of where reading actually stops — and that map is what lets you size long prompts safely instead of discovering the edge in production.