CONCEPT Four rules that break prefills
Prefilling is powerful (6.1–6.4) but hemmed in by hard constraints. Miss one and you get a 400 error, an unparseable response, or silently wrong output. These four are the ones the exam leans on.
| Rule | Consequence if violated |
|---|---|
| Prefill text must not end with trailing whitespace | Request rejected |
| Prefill is not available with extended thinking | Cannot combine the two |
| Final assistant text = prefill + generation | Parse fails if you forget to prepend |
| Unsupported on Claude 4.6+ / Fable 5 / Mythos (last turn) | 400 error |
CONCEPT Rule by rule
"The answer is " (note
the trailing space) is invalid. End on the last non-space character: "The answer is". Same for
tabs and newlines — "{\n" is out; use "{".content. The complete assistant message is your prefill concatenated with the
generated text. Whenever you parse or store the reply, prepend the prefill — and if a stop
sequence stripped the closing delimiter (6.4), add that back too.DIAGRAM Decision: can I prefill this request?
or an instruction instead"] M -->|"no (earlier model)"| T{"Extended thinking on?"} T -->|"yes"| NO["🔴 Incompatible — turn off thinking
or drop the prefill"] T -->|"no"| W{"Prefill ends in whitespace?"} W -->|"yes"| FIX["🟠 Trim trailing space/newline"] W -->|"no"| OK["🟢 Valid — remember:
final = prefill + generation"] FIX --> OK classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; classDef bad fill:#f8d7da,stroke:#dc3545,color:#721c24; class OK ok; class SO bad; class NO bad; class FIX gate;
CODE BAD prefills → GOOD prefills
# ❌ trailing space → rejected {"role": "assistant", "content": "The answer is "} # ✅ trim it {"role": "assistant", "content": "The answer is"} # ❌ prefill + extended thinking in the same request → not allowed resp = client.messages.create( model="claude-opus-4-5", max_tokens=1024, thinking={"type": "enabled", "budget_tokens": 2000}, messages=[{"role": "user", "content": "..."}, {"role": "assistant", "content": "{"}], # incompatible ) # ❌ parsing without prepending the prefill json.loads(resp.content[0].text) # starts at '"name"...' → error # ✅ reconstruct: prefill + generation (+ stopped delimiter) json.loads("{" + resp.content[0].text + "}") # ❌ last-turn prefill on a new model → 400 # model="claude-opus-4-8", messages=[..., {"role":"assistant","content":"{"}] # ✅ replacement on new models: Structured Outputs resp = client.messages.create( model="claude-opus-4-8", max_tokens=300, output_config={"format": {"type": "json_schema", "schema": schema}}, messages=[{"role": "user", "content": "Return {name, id} for Ada."}], )
TRADE-OFFS Keep prefill (legacy) vs. move to the modern path
| Prefill (earlier models) | Modern replacement | |
|---|---|---|
| Format control | Prefill { / a tag | Structured Outputs (output_config.format) |
| Skip preamble | Prefill the first word | System instruction: "no preamble" |
| Persona | Prefill [Name]: | System-prompt persona + instruction |
| Works with thinking? | No | Yes |
| Works on 4.6+ / Fable? | No (400) | Yes |
EXAM TRAPS
content and you're done." → The final message is
prefill + generation. Prepend the prefill (and re-add any stop-sequence delimiter) before parsing.PRACTICE
Q1 · Why is {"role":"assistant","content":"Answer: "} rejected?
The prefill ends in trailing whitespace (the space after the colon), which is not
allowed. End on the last non-space character: "Answer:".
Q2 · Can you prefill and use extended thinking together?
No — prefilling the assistant turn is not available with extended thinking enabled. The model produces its own thinking block first, so there's no partial assistant message for you to seed. Pick one.
Q3 · Your prefill request 400s on claude-opus-4-8. What's wrong and what do you do?
Last-turn prefill is unsupported on Claude 4.6-and-newer models (and Fable 5 /
Mythos), so it returns a 400. Switch to the modern equivalent: Structured Outputs
(output_config.format) for JSON shape, or a clear system/user instruction for preamble-skipping
and persona. Assistant messages earlier in the conversation are still allowed.