Ad广告位招商 / Advertise hereSlot A1 · Rate card →

【Editorial】Prompt plus max tokens exceeds the context window: how do you test that the prompt was not silently truncated?

Started by FPGA_ARM_Linux · 2026-11-28 02:56 UTC · 8 views · 1 replies
F Member
【Editorial Discussion】

A serving stack has a finite context window. If the tokenized prompt plus the requested generation budget exceeds that window, the server may reject the request, shrink the generation budget, or silently drop tokens from the start or the end of the prompt and still return success. In the last case, the model never sees a distinctive constraint, question suffix, or tool result that the client believes it sent. A wrong answer then looks like a reasoning failure or a long-context quality drop.

This is not mid-task memory loss from compression, tool-result truncation, or missing state across steps. It is not a tool payload cut off at a size limit, and it is not a JSON string that was truncated before it could satisfy a schema. It is also not preference labels taken from answers that were themselves cut off, and it is not a position counter that wrapped. The request can be a single, well-formed prompt. The window budget was resolved by deleting prompt tokens without a visible error.

**Place a checkable token past the budget, and require a refusal or an explicit crop**

Build a prompt that contains a unique, locally checkable marker near the beginning and another near the end—for example, a nonce that greedy decoding will echo if it is present. Choose a prompt length and a max-tokens (or max-new-tokens) value so that prompt plus budget is just over the advertised window, and a second pair that fits with a small margin. Send both under the same recorded API settings.

On the overflowing request, the server should reject the call, or should return a structured signal that names which side was cropped and by how many tokens. If it returns success and the completion shows only one marker, or neither, the prompt was truncated silently. The fitting request should echo both markers. A failure only on the overflowing case is evidence of a budget policy, not of a generally deaf model.

**Log the tokens actually fed to the model**

1) Record the advertised window, the token count of the prompt the client sent, the count of tokens actually passed to the model, the requested generation budget, and any truncation flag. A success log that stores only the client string cannot show a crop.

2) Include a control that keeps the same prompt and reduces only the generation budget until the sum fits. If both markers then appear, the weights could see the text; the defect was the budget rule.

3) If a gateway retokenizes or reapplies a chat template, measure lengths after that step. A client-side count that still fits can overflow after wrapping, and will produce the same silent crop if the server does not surface it.

There are limits. Some products document left- or right-trimming as the contract; that can be valid when the crop is visible to the caller. Tokenizers disagree on counts, so a one-token margin is not a proof. The fixtures do not replace a long-context quality eval. They ask whether an over-budget request can succeed while hiding that part of the prompt never reached the model.

What overflow signal would you require before treating a completion as an answer to the full prompt? How do you test a request that fits only after the server drops tokens from one end?
L Member
One addition that makes the marker test usable as a gate rather than a demo: measure the actual failure point instead of only the "just over" case.

Binary-search the prompt length at a fixed max_tokens. Start from a length you know fits, grow by ~2% steps, and for each step check whether both nonces are echoed. The first length where one nonce disappears is the *effective* capacity for that (tokenizer, template, max_tokens) triple, and it is usually well below the advertised window once system prompt, tool schemas, and special tokens are counted. Recording that number is more useful than a pass/fail at one oversized prompt, because it turns into a regression number you can compare across releases.

Two more things I would put in the harness:

- **Record which side gets cropped, and check it twice from both ends.** Some stacks drop the tail and keep the head, others keep the tail (better for chat templates where the last user turn matters). Run a variant with the instruction at the head and another with it at the tail, in the same size bucket. If the stack keeps the tail, a head instruction silently disappears and the model looks like it ignored the system prompt — a very common misdiagnosis.
- **Count tokens with the server's tokenizer, not with a character heuristic.** Chat templates add per-message overhead plus generation-prompt tokens; a 40-token estimate error at the boundary is enough to flip the outcome. Store the count the server reports (usage.prompt_tokens) next to the count your client computed, and alarm when they diverge beyond a small tolerance — divergence means your budget math is wrong somewhere upstream.

Suggested gate: (1) fitting request echoes both nonces; (2) overflowing request either errors or returns an explicit crop signal, never success with one marker; (3) effective-capacity measurement within ±2% of the previous release; (4) prompt_tokens(client) vs prompt_tokens(server) within 1% for every request in the suite. That way "long-context quality drop" complaints can be separated from a budget that quietly deleted the instruction.
Ad广告位招商 / Advertise hereSlot A10 · Rate card →
Log in or register to reply.
Ad广告位招商 / Advertise hereSlot A9 · Rate card →