Model and Inference Engineering · Staff
A stop string appears inside the answer. Why did the server return half a JSON object?
The question
Interview question
A gateway uses `END` as a stop string for a model response. The assistant is producing JSON with a quoted field containing a customer code such as `WEEKEND42`. Generation stops at the substring `END`. The returned bytes are incomplete JSON, even though the model would have closed the string and object. Why did a string inside a value become a control signal?
Take a few minutes to form your approach. Then open a worked answer and compare the decisions.
Reveal a worked answer
The stop condition belongs to the serving layer, which can scan generated text for a matching sequence. It does not necessarily parse the JSON grammar before deciding to stop. A text stop string can therefore match inside a quoted JSON value or across token boundaries, depending on the engine's matcher. vLLM's sampling parameters distinguish stop strings, stop token IDs, and whether a matching stop string is included in returned text. The precise matching and streaming behavior must be checked in the deployed version. The parser downstream sees only what the gateway returned.
I would reproduce with the exact tokenizer, stop configuration, output mode and streaming adapter. Capture the completion finish reason and the raw generated token IDs if the engine exposes them safely. Did generation stop at a literal string, a special end-of-turn token, the max-token limit, or a network cutoff? Those all look like a partial JSON to a naïve caller but need different fixes. Compare the engine output with the gateway's streamed chunks and final assembled response. If the gateway also applies its own stop matching, there may be two places truncation can occur. Do not diagnose a model formatting problem solely from the final parsed error.
An arbitrary printable stop word is a poor boundary for structured content that may contain that word. Prefer a protocol with a dedicated end-of-message or end-of-turn marker when the model and engine actually support it, or let constrained generation reach a valid completion and use a parser to validate it. A schema-constrained decoder can prevent certain malformed continuations, but a separate text stop matcher can still interrupt it, depending on pipeline order. Verify that interaction instead of assuming the grammar takes precedence. If the output is truncated, retry under a corrected contract or return an error. Never treat the partial object as a valid tool action.
The interviewer may suggest escaping the customer's value in the prompt. That does not guarantee a model will never emit the stop bytes somewhere else, and stop matching may see the serialized escaped form differently. Test strings that cross token and stream-chunk boundaries, quoted strings, Unicode, and output at the token limit. This question is about the termination contract, not whether a syntactically valid tool call is a wise decision. The latter is already covered by JSON always parses, but the agent still makes bad calls.
Continue reading
Related questions
Read beyond the question
Explore more model and inference engineering
Follow another question in this area, or search the complete Question Library.
Browse this area →Browse Question Library →