<< Home | Prompting craft
Stop extraneous model output and enforce templates (95% success rate)
| Area | Prompting craft |
| AI used | Any |
| Source | Reddit thread |
| Posted | unknown |
The move
Add stop tokens, multi-shot examples, and response prefixes to enforce strict output templates.| When this works | When it doesn't |
|---|---|
| A smaller LLM (such as an 8B model) generates unwanted filler text or fails to follow strict formatting templates. It works when prompt tags are correctly formatted and output can be constrained. | The prompt tags are misplaced or missing due to RAG errors, or the prompt requires multi-character chat logic that exceeds the capability of smaller models without fine-tuning or specialized tools. |
Key details
- \n\n
- solves 95% of the 'It won't stop writing' problems
- multi-shot examples
- GBNF grammar
Prompt for your AI
Instructions for enforcing strict output templates and preventing filler text:
1. Verify Prompt Integrity: Check that instruction tags are placed correctly and that context or RAG components are not inserting blank strings or corrupted text before sending to the model.
2. Define Explicit Stop Tokens: Add a stop token to mark the exact end of your desired message. Use `\n\n` when only a single paragraph is required, or set an explicit final token sequence for multi-line outputs to solve generation overruns.
3. Provide Multi-Shot Examples: Include concrete multi-shot examples in the prompt showing the exact desired layout to demonstrate the target structural template.
4. Prefix the Assistant Response: Prefill or start the assistant's response with the expected opening tag or character name so the model immediately follows the required format.
5. Apply Inference Guidance or Orchestration: Use token-level guidance tools like Outlines, Guidance, or a GBNF grammar. If complex multi-step outputs fail, break generation into multiple sections using DSPy or offload multi-character turns to dedicated tools like SillyTavern or larger 70B models.
Before you give me the final result, check with me:
- Verify instruction tags are placed correctly and RAG inputs are not blank.
- Confirm a stop token like \n\n or an explicit end sequence is configured.
- Ensure multi-shot examples demonstrate the exact requested output format.
- Check if the model parameter size (e.g. 8B vs 70B) requires external grammar constraints or SillyTavern.
What happened
A user tried to force Llama 3 to format character dialogue with stats without generating filler conversational text. Implementing stop tokens, multi-shot examples, and response prefixing constrained the model output to the required template.Who confirmed it
This solves 95% of the 'It won't stop writing' problems.Give it to your agent
Read https://howtheyuse.ai/p/force-strict-output-formatting-and-stop-extraneous-text.md and help me do this.