C.W.K.
Stream
Lesson 02 of 10 · published

System / Developer / User / Assistant Prefill

~14 min · conversation, layers, prefill

Level 0Apprentice
0 XP0/100 lessons0/14 achievements
0/120 XP to next level120 XP to go0% complete

Five places to put words

  • System — operator's constitutive frame. Persistent.
  • Developer — app-level instructions (OpenAI explicit, others implicit inside system).
  • User — human input. Untrusted.
  • Assistant — what the model said. Reused as context next turn.
  • Assistant prefill — you start the assistant's reply for them. The model continues from there.

What prefill is good for

  • Forcing JSON outputs without strict mode (start with {).
  • Skipping preambles (start with the actual answer).
  • Persona enforcement (start in voice).
  • Format anchoring (start with the table header, the bullet, the heading).

Provider quirks

Anthropic supports prefill via the last assistant message in the conversation. OpenAI supports it via the prior assistant turn (not as a first-class param). Gemini supports it via the model role. The mechanism is the same; the API surface differs.

Code

Anthropic prefill·python
client.messages.create(
    model="claude-opus-4-7",
    messages=[
        {"role": "user", "content": "List three risks."},
        {"role": "assistant", "content": "{\n  \"risks\": ["}  # prefill
    ],
)
# Model continues from "{ \"risks\": ["

External links

Exercise

On a prompt that frequently includes preamble ("Sure, here is..."), add an assistant prefill that starts directly with the answer. Compare three sample outputs.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.