Skip to content

Interview question · Model API Foundations

A JSON summary sometimes lists one ticket where there were three, with no prompt change. Find the cause.

A debugging question about the field most harnesses never read. The strong answer finds a length stop behind a reply that parses, explains how a repair step made it wrong, and fixes the loop so truncated output never becomes a valid object.

mediumNewUpdated Nov 2026

TL;DR: The reply was cut off by max_tokens mid-array, a lenient JSON repair step closed the brackets, and the result was a valid object with one ticket instead of three. The stop reason said length the whole time. Branch on the stop reason before parsing, treat a length stop as no output, retry with more room or a smaller task, and never let a repair step run on truncated text.

How to approach it

This is a trace-reading question. Ask for the raw response of a bad run, or say what you would look at: the stop reason and the usage, then the text. Resist the pull toward the prompt, because the symptom is intermittent with no prompt change, which points at something that varies per call: the length of the output, the length of the input, or the server.

A strong answer

Name the suspect from the symptom. "Sometimes one ticket where there were three" with no prompt change is the fingerprint of truncation plus repair: the output was long enough to be cut on busy accounts and short enough to finish on quiet ones, and something downstream made the cut-off text parse.

Walk the run:

Trace
A length stop, repaired into a wrong answer
  1. 01userSummarise the open tickets for account 2210 as JSON.
steps 0tool calls 0writes 0context 0 tok
1/6

user

Summarise the open tickets for account 2210 as JSON.

Explain why nobody saw it. The harness read content, parsed it, and when parsing failed it repaired. The one field that said "this is incomplete" was never read. A length stop is the only reliable signal of truncation, because truncated prose looks finished and truncated JSON, once repaired, looks finished too.

Then fix it in the right order:

  1. Read the stop reason before parsing. On length, the output is absent, whatever the text looks like.
  2. Remove repair from the path for structured output, or restrict it to failures with a stop reason (a stray code fence, trailing text), where the model finished and the shape is merely messy.
  3. Choose max_tokens from the task rather than a default: three tickets with summaries need room, and the latency budget says how much is available (Timeouts, max_tokens and Deadlines per Step).
  4. If the task can exceed any sensible allowance, change the task: ask for ids first and summaries per ticket in separate calls, or paginate.
  5. Record the stop reason on the trace span so the next person can see truncation at a glance.
import json

def parse_structured(text, stop):
    if stop == "length":
        return None, "truncated: retry with more room or a smaller task"
    try:
        return json.loads(text), "ok"
    except json.JSONDecodeError as e:
        return None, f"invalid json at char {e.pos}: ask the model to fix it"

cut = '{"tickets": [{"id": "T-1", "status": "open"}, {"id": "T-2",'
obj, why = parse_structured(cut, "length")
print(obj, why.split(":")[0])  # => None truncated
print(parse_structured('{"tickets": []}', "stop")[1])  # => ok

Say what the provider's structured-output mode does and does not give you. Schema enforcement guarantees that completed output matches the schema. It does not stop the output being cut off when the allowance runs out; a truncated schema-constrained reply is still truncated. The stop reason is still the field to read (Structured Outputs and Constrained Decoding).

What interviewers probe next

"Why did it happen only sometimes?" Output length varies with the data: accounts with long ticket summaries overran the allowance, accounts with short ones did not. The variation was in the task, not the prompt.

"Could you detect it from the text alone?" Not reliably. Unbalanced brackets are a hint for JSON and useless for prose. The stop reason is the signal, which is why it is read first and recorded on the trace.

"What about asking the model to keep the output short?" It reduces the frequency and leaves the mechanism in place. The next long account truncates again. Fix the branch and size the allowance.

How it's scored

Weak: Edits the prompt to ask for all tickets, or blames the model, without reading the stop reason.

Hire: Identifies the length stop, connects it to the repair step, and makes the loop treat truncation as no output.

Strong Hire: Also sizes max_tokens from the task and the latency budget, restructures the task when it cannot fit, records the stop reason on the trace, and explains why schema mode does not prevent truncation.

Common mistakes

  • Parsing before reading the stop reason.
  • A lenient repair step that runs on any parse failure, including truncation.
  • A default max_tokens that nobody chose for this task.
  • Prompting for brevity as the fix for an allowance problem.
  • Assuming structured-output mode protects against cut-off replies.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 6, and the site remembers where you stopped in each one.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in raises your free answers from 5 to 6 per topic, adds an applied lesson in every topic and easy practice tests, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented. Post a correction or another way to answer.