<< Home | Prompting craft
Force LLMs to start responses with an exact prefix
| Area | Prompting craft |
| AI used | Any |
| Source | Reddit thread |
| Posted | unknown |
The move
Pre-fill the assistant response turn or use completion APIs, llama.cpp grammars, and dialogue few-shotting to enforce an exact output starting string.| When this works | When it doesn't |
|---|---|
| You need an LLM to generate text directly without introductory preamble or conversational filler, such as captioning a photo. Works best when using Completion APIs, local inference engines with grammar constraints, or Chat APIs that permit pre-filling assistant messages. | The Chat API endpoint automatically inserts an end token like `<|im_end|>` to cut off pre-filled assistant blocks and starts a new assistant turn. It also fails if strict API schema validation rejects pre-filled assistant roles. |
Key details
- Completion API
- llama.cpp
- dialogue few-shot
- <|im_start|>assistant
Prompt for your AI
You are an output-formatting controller designed to force exact response prefixes and eliminate conversational preamble.
When direct prefix enforcement is needed, apply these mechanisms:
1. System Prompt Rule: Instruct the model to begin every response immediately with the specified prefix phrase without introductory text, greetings, or conversational filler.
2. Dialogue Few-Shot: Provide prior conversational turns where assistant replies begin with the target prefix phrase to increase the model's likelihood of continuing the pattern.
3. Payload Pre-fill: In raw chat templates, append the target prefix directly after `<|im_start|>assistant\n` or inside the assistant message payload so generation resumes mid-sentence.
4. Engine Constraints: Switch to a Completion API or use llama.cpp grammar enforcement if chat API endpoints reject pre-filled assistant messages.
Decision Points:
- If the API accepts an assistant message payload without injecting an end token, pre-fill the assistant turn with the prefix.
- If the endpoint appends `<|im_end|>` and splits the assistant block, switch to Completion API, grammar constraints, or dialogue few-shotting.
Guardrails:
- Never include preamble text before the required starting string.
- Ensure the generated completion connects seamlessly to the forced prefix.
Before you give me the final result, check with me:
- Verify whether your API endpoint allows pre-filling assistant message content without auto-appending an end token.
- Check if switching to a Completion API or llama.cpp grammar constraint is required if the Chat API splits assistant turns.
- Ensure dialogue few-shot examples consistently start assistant responses with the target prefix phrase.
What happened
A user wanted to caption a photo without preamble like 'This is a picture of' remaining in the final text. They tried pre-filling the payload assistant block with `<|im_start|>assistant\nThis is a picture of`, but encountered endpoints cutting it off with `<|im_end|>`. Solutions proposed included using Completion APIs, llama.cpp grammars, or dialogue few-shotting.Who confirmed it
The poster noted that by changing the assistant block to start with 'This is a picture of', they could force the model to generate the description directly.Give it to your agent
Read https://howtheyuse.ai/p/force-model-to-start-with-specific-text.md and help me do this.