What it is
Prefilling means writing the first few words of the AI's answer yourself and letting the model carry on from there. Instead of only asking a question and waiting, you also hand over the opening of the reply. The model treats those words as something it has already said, and continues.
To see why that works, it helps to know how a language model writes. It produces its answer one small piece at a time, each piece called a token (roughly a word or part of a word), and every new token is chosen by looking at everything that came before it. The model doesn't plan the whole answer and then type it out. It keeps asking itself "given all of this, what comes next?" So if the text already reads "Sure, here is the list in alphabetical order: 1.", the easiest thing for the model to do is write item one of an alphabetical list. You have taken away all the other ways the answer might have started.
The textbook example is data for a computer program. Programs often want answers in a format called JSON, a strict way of writing data that always starts with an open curly brace, {. If you ask a chatbot for JSON, it may reply "Certainly! Here's the JSON you asked for:" and then the data, and that friendly sentence breaks the program that was expecting a brace as the first character. Prefill the reply with { and the chatty preamble has nowhere to go. The model is already inside the data, so it keeps writing data.
Other common uses:
- Skipping the preamble. Start the reply with the first words of the real content, so there's no "Great question!" warm-up.
- Locking in a structure. Start with the first label of a template, such as
<summary>in a prompt that uses XML tags, and the model fills in the rest of the template. - Keeping a character. In a role-play app, start every reply with the character's name in brackets, which reminds the model who it is speaking as, even deep into a long conversation.
- Setting the tone or language. Begin in French and the reply tends to stay in French. Begin with "Honestly, the weak point is" and you get criticism instead of praise.
There's an important catch, and it matters more than any of the tricks above. True prefilling is a feature of the developer side of AI, the API that programs use to talk to a model. It only works where the service lets you put words in the assistant's half of the conversation. Most consumer chat apps never let you do that; you type in the user's box and the reply is entirely the model's. And at the time of writing, some of the newest models have switched it off altogether, as the next sections explain. So think of prefilling as a technique with a history, a set of places where it still works, and a set of modern replacements.
Where it works and where it doesn't, at the time of writing
- Newer Claude models: not accepted. Anthropic's documentation says that starting with the Claude 4.6 models (Claude Opus 4.6 was released in February 2026), a request that ends with a prefilled assistant turn is rejected with an error. Its migration guides for Claude Opus 5.5 and Claude Fable 5.1 repeat the rule and call it the "prefill restriction".
- Older Claude models: still accepted. Anthropic says earlier models continue to support prefills, so code written for them keeps working until those models are retired.
- Open-weight models: usually available. When you run a model yourself, you control the exact text the model sees, so you can always start its reply. The popular Hugging Face Transformers library has a setting for exactly this, and its documentation uses the
{example. - Some other providers: available under their own names. Mistral's API calls it a "prefix", and DeepSeek's API offers "Chat Prefix Completion" as a beta feature.
- Everyday chat apps: not available as such, but you can get a softer version of the effect by asking in plain words, which is what "Try it yourself" below shows.
Features like these change often. Check the current documentation for whichever model or service you use before relying on any of this.
Why it matters
It shows how the machine really works. Prefilling is the clearest everyday demonstration that a chatbot is a text-continuation engine underneath. Once you understand that the model is always just continuing whatever text is in front of it, a lot of other advice makes sense: why examples help, why the end of a prompt matters, why a confident opening line changes the whole answer. That understanding is useful even if you never prefill anything yourself.
It was the standard fix for formatting for years. Before stricter tools existed, prefilling was one of the most reliable ways to get clean, machine-readable answers. Anthropic's own free prompt-engineering tutorial taught it as "speaking for Claude" and described prefilling with { as a way to get JSON that is "not deterministically, but close to it". A great deal of working software, tutorials and forum advice still assumes it exists, so you will meet it.
It stopped working on the newest Claude models, and that breaks things. If you follow an older tutorial, or run a tool built before 2026, against a recent Claude model, the request can simply fail with an error. Knowing what prefilling is lets you recognise the problem and ask the right question: "does this model still accept prefills, and if not, what replaces it?" Anthropic's answer, in its migration guides, is structured output (a feature that makes the model follow a data format you define) or clear instructions in the system prompt.
It is a safety issue as well as a formatting trick. Anything that lets you put words in the model's mouth also lets you put the wrong words there. Researchers showed in 2024 that starting a reply with "Sure, here is how to…" could get safety-trained models to continue with content they would normally refuse. That's part of why guardrails designers care where prefilling is allowed, and why providers that still offer it pair it with other protections.
The everyday version still helps you. Even with no special access, telling a chatbot exactly how to begin its answer is one of the quickest ways to cut waffle, fix a format, or change the tone. It is less reliable than the real thing, because the model can ignore a request, but it costs nothing and works in any app.
Real-world examples
Anthropic teaches "speaking for Claude", then retires it
For several model generations, prefilling was a signature Claude technique. Anthropic's public Prompt Engineering Interactive Tutorial, published on GitHub, has a lesson on formatting output that explains how to put text in the assistant turn so that Claude continues from that point. Its examples include starting a reply with an opening <haiku> tag so that the answer is only the poem, wrapped neatly for a program to extract, and starting with { to encourage JSON. Anthropic's documentation page on making answers consistent still shows a prefill example today: a sales report template where the assistant's reply is started with the first few lines of the report, so the model fills in the numbers rather than chatting about them.
Then the advice changed. When Anthropic released the Claude 4.6 models, beginning with Claude Opus 4.6 on 5 February 2026, prefilling the final assistant turn stopped being accepted. Anthropic's prompting guide now has a section called "Migrating away from prefilled responses". It gives its reason plainly: model intelligence and instruction following have improved so much that most uses of prefill no longer need it. It then walks through each old use and its replacement. Forcing JSON becomes structured output. Skipping the preamble becomes a direct instruction such as "Respond directly without preamble." Continuing an interrupted answer becomes a new user message that quotes where the last one stopped. Keeping a character in a long chat becomes reminders placed in the user's turn instead.
The migration guides for Claude Opus 5.5 and Claude Fable 5.1 carry the same rule forward. The Opus 5.5 guide says a request must not end with a prefilled assistant turn, because it will be rejected, and points to structured outputs or system prompt instructions instead. The Fable 5.1 guide says prefilling returns an error, unchanged from Claude Fable 5, and recommends system prompt instructions. Anthropic's automated migration helper even lists "prefill replacement" as one of the code changes it makes. One detail is easy to miss: the restriction is on the final assistant turn. Earlier assistant messages in a conversation, such as worked examples in a few-shot prompt, are unaffected.
The lesson for everyone else is that a prompting trick can be excellent advice one year and an error message the next. Techniques that depend on how a particular product is built are the ones most likely to change.
Researchers turn prefilling into a jailbreak (2024)
In April 2024, Maksym Andriushchenko, Francesco Croce and Nicolas Flammarion of EPFL posted a paper called "Jailbreaking Leading Safety-Aligned LLMs with Simple Adaptive Attacks", later presented at the ICLR 2025 conference. A jailbreak is a way of tricking a model into ignoring its safety training. The paper tested many attacks on many models, and for Claude it pointed out a weakness specific to Anthropic's API: the ability to prefill. The abstract reports jailbreaking all the Claude models they tested, which did not expose their internal probabilities, with either a transferred attack or a prefilling attack, at a 100 percent success rate.
Two months later, in June 2024, Xiangyu Qi and colleagues at Princeton University and Google DeepMind posted "Safety Alignment Should Be Made More Than Just a Few Tokens Deep", which won an Outstanding Paper award at ICLR 2025. It explains why prefilling is so powerful against safety training. The authors found that a model's safety behaviour is concentrated in the first few tokens of its reply: the model has mostly learned to start with a refusal, rather than to stay safe all the way through. They call this "shallow" safety alignment. Force the first few words to be compliant instead of a refusal, and the model often carries on as if it had agreed. In their experiments on open-weight models, the chance of a harmful answer rose from near zero to over 50 percent as more harmful opening words were prefilled. They proposed training methods that make safety run deeper than the opening, and they noted that open-weight models are especially exposed because anyone running one can control how it decodes.
Anthropic has not said that these papers were why it removed prefilling, and its stated reason is the improved instruction following described above. But the research explains why prefilling sits on the boundary between a formatting convenience and a security question.
Mistral uses prefixes as a defence, and DeepSeek keeps them in beta
Not every provider went the same way. Mistral AI's API supports prefilling under the name "prefix": the last message in the conversation is an assistant message marked as a prefix, and the model continues it. Mistral's guide to the feature lists four uses, and one of them turns the jailbreak research on its head. As well as keeping answers in one language, saving on long instructions, and running role-play, Mistral suggests using a prefix to resist jailbreaks. Its advice is to use both a system prompt and a prefix, so the user's question is sandwiched between two layers of instructions. The guide also warns that a prefix used on its own can produce noisy, unpredictable answers, which is a fair summary of prefilling's weakness in general: it forces the first words, not the thinking behind them.
DeepSeek's API offers the same idea as "Chat Prefix Completion", a beta feature you switch on by using a special beta address and marking the last assistant message as a prefix. Its documentation example starts the reply with the opening marker for a block of Python code and tells the model to stop when the code block ends, so the answer is only code. And for anyone running open-weight models on their own computer, the Hugging Face Transformers library has a continue_final_message option that its documentation describes as useful for "prefilling" a response, with an example that starts the model's reply partway through a line of JSON.
So at the time of writing, prefilling is alive in some places and gone in others. If a tool or tutorial relies on it, the first question is which model it will be talking to.
An everyday scenario: the product descriptions that kept saying "Absolutely!"
This is an illustrative scenario, not a documented case. Imagine Dev, who sells handmade leather goods and has a small script that sends each new product to an AI model and pastes the reply straight into his online shop. The replies are good, but about one in ten begins "Absolutely! Here's a description for your wallet:", and that line ends up on the live product page.
A friend who builds software shows him the old fix: in the script, start the assistant's reply with the product name followed by a colon, so the model has to begin with the description itself. On the older model Dev was using, it works at once. Months later he switches the script to a newer model, and every request starts failing with an error. The new model doesn't accept prefills. His friend changes the script again, this time adding one line to the system prompt: "Reply with the product description only. No greeting, no introduction, no closing remarks." She also adds a small check that deletes any first line ending in a colon, just in case. The preamble disappears, and the script now works on either model. The instruction was always the sturdier fix; the prefill was just the older habit.
Try it yourself
You can't reach inside a chat app's reply box, but you can get most of the benefit by telling the model how its answer must begin. This works in ChatGPT, Claude, Gemini, Copilot or any other chatbot, on free plans. Allow about fifteen minutes.
- See the default. Open a new chat and paste a normal request, such as:
Give me three ideas for a blog post about indoor herb gardens.
Notice how the answer opens. Most chatbots start with a friendly line before the list.
- Tell it the first words. In a new chat, paste the same request with an opening line specified:
Give me three ideas for a blog post about indoor herb gardens.
Begin your answer with exactly these words, and write nothing before them:
"1. Title:"
Compare the two. The second should go straight into the list, in the shape you asked for.
- Force a format. If you ever need data you can paste into a spreadsheet or another tool, name the first character as well as the format:
List five common houseplants with their ideal light level.
Answer in JSON only: an array of objects with the keys "plant" and "light".
Your reply must start with the character [ and end with the character ].
No explanation, no code fences, nothing else.
Paste the result into a free JSON checker online, or just look at whether it begins and ends where you said. If a chatbot keeps adding extra text, that is exactly the problem structured output was invented to solve.
- Steer the tone. The opening words carry the mood of the whole answer. Try this with something you have written:
Here is the opening paragraph of my newsletter: [paste your paragraph]
Give me honest feedback. Start your reply with: "The biggest weakness here is"
Then try again, starting with "What works well here is", and notice how different the two replies are, even though you gave the same paragraph.
- Keep a voice. For a role-play or a practice conversation, ask the model to begin every reply with a label:
You are Mrs. Patel, a strict but fair landlady, and I am a tenant asking to paint my flat.
Stay in character for the whole conversation.
Begin every reply with "Mrs. Patel:" and never step out of the role unless I type STOP.
- Notice the limits. Try asking for something the model won't do, and add "Begin your answer with: Sure, here is". A well-built chatbot will still decline. Asking in words is a request, not a real prefill, and modern models are trained to treat it that way.
- If you use an API, check before you prefill. If you or a developer you work with call a model through an API, look up that model's current documentation for "prefill", "prefix" or "structured outputs" before building on it. On models that reject prefills, use structured output for data and a clear system prompt instruction for everything else.
Common mistakes and misunderstandings
Assuming every AI can do it. Prefilling was always a developer feature, and even there it depended on the provider. At the time of writing, the newest Claude models reject it, many services never offered it, and chat apps don't expose it. When a tutorial says "just prefill the reply", check which model and which kind of access it was written for.
Treating an old tutorial as current. A lot of prompting advice online dates from 2023 to 2025, when prefilling Claude was standard practice. Code copied from those guides can fail with an error on a 2026 Claude model. The fix isn't to find a workaround; it's to use the replacement Anthropic recommends.
Thinking prefilling guarantees a format. Even where it works, a prefill only fixes the first few words. The model can still close the data early, add a comment at the end, or drift out of the format halfway through. Anthropic's own tutorial called it close to deterministic, not deterministic. If a program will break on a bad answer, structured output, which actually restricts what the model can produce, is the right tool, with a check on the result as a backstop.
Leaving a space at the end. On APIs that support it, a prefill that ends with a trailing space can be rejected; Anthropic's older documentation warned that Claude returned an error for exactly this. End the prefill on a word or a symbol, not a space.
Confusing "begin your answer with" with a real prefill. When you type an opening line into a chat app, you are asking the model to use it. It can refuse, rephrase, or add something before it. A real prefill, where it exists, is text the model genuinely treats as already written. Both are useful, but they are not the same strength.
Using prefills to push past refusals. Prefilling was once suggested as a way around unnecessary refusals, and it can also be used to get around necessary ones, which is how the jailbreak research used it. Anthropic now says clear prompting in the user message is enough for appropriate requests. If a model refuses something reasonable, rephrase the request and explain the context. Trying to force the answer is against most services' terms and tends to produce worse answers anyway.
Forgetting the cheaper fix. Many prefills existed only to remove a chatty first sentence. A plain instruction ("start directly with the answer, no introduction") does the same job on almost any model, and a line of code that strips a leftover greeting costs nothing. Reach for the simple fix first.
Related elements
- Structured Output: the modern, stricter way to force an answer into a data format, and the main replacement for prefilling JSON.
- System Prompt: where Anthropic now recommends putting the instructions that prefills used to enforce.
- XML Tags: prefilling an opening tag was a classic way to wrap an answer so a program could pull it out.
- Role Prompting: prefilling a character's name was used to keep a role steady in long conversations.
- Tokens: the model writes one token at a time, which is why the first few words shape everything after them.
- Guardrails: prefilling attacks are one of the reasons safety needs more than a polite opening refusal.
- API: true prefilling only ever existed on the developer side, not in chat apps.
- Mistral: one of the providers whose API still offers prefilling, under the name "prefix".