Context and Constraints
On this page
Context: Give the model what it doesn’t know
Mistral models have extensive general knowledge, but they know nothing about your specific situation: your company, your project, your audience, your business constraints. The context you provide in your prompt bridges this gap. This is what makes the difference between a general-purpose tool and a specialized assistant. Without context, the model produces generic answers—correct on average, unusable in particular. With the right context, it produces tailored responses.
Three types of context to provide
The first is situational context: the situation surrounding your request. A marketing director who simply writes “propose a marketing plan” will get a textbook plan. If they specify their situation, everything changes:
Context: I am the marketing director of an SME with 50 employees
specializing in B2B office furniture sales.
We are launching a new eco-friendly line in September 2026.
Our annual marketing budget is €80,000.
Each sentence in this context eliminates dozens of off-topic answers: no B2C strategies, no seven-figure budgets, no recommendations unrelated to the launch.
The second is document context: the data the model must analyze or use. The model doesn’t know your internal figures—you have to give them to it, ideally delimited by tags to separate them from instructions:
Here are the quarterly results to analyze:
<data>
Q1 2026: Revenue €1.2M, margin 23%, 145 new clients
Q2 2026: Revenue €1.5M, margin 21%, 178 new clients
Q3 2026: Revenue €1.1M, margin 19%, 112 new clients
</data>
Identify trends and propose 3 corrective actions for Q4.
The third is audience context: who the generated content is for. You don’t explain the same topic the same way to a beginner and an expert. Specify, for example: “The text is for experienced Python developers (5+ years of experience) discovering language model APIs for the first time. No need to explain Python basics, but detail LLM concepts.” The model will then calibrate its level of detail exactly where your reader needs it.
Define the expected format
Output format is one of the most powerful constraints. Without guidance, the model will choose a default format—often prose—that you’ll have to rework. By specifying the format, you get exactly what you need, ready to use.
For a list, say so: “List the advantages as bullet points (5 maximum).” For a table: “Present the results in a Markdown table with columns Feature | Availability | Priority.” For software integration, structured JSON is king, and it deserves to be specified field by field:
Return the response in the following JSON format:
{
"summary": "string (max 100 words)",
"keywords": ["string"],
"sentiment": "positive | neutral | negative",
"confidence_score": "number (0-1)"
}
The same principle applies to code: “Write the function in Python 3.11+. Add Google-style docstrings and type hints. Include 2 usage examples in comments at the end.” The more precisely you describe the format, the less rework you’ll have to do.
Constrain length
Mistral models tend to be exhaustive if you don’t set limits. You can constrain length by word count (“Respond in 150 words maximum”), by structure (“Respond in exactly 3 paragraphs of 2-3 sentences each”), or by elements (“Give exactly 5 recommendations, each in one sentence”).
One warning, however: language models count words and characters poorly. Asking for “exactly 150 words” will produce text of about 150 words, rarely spot on. If length really matters to you, prefer structural constraints—number of paragraphs, points, sections—which the model follows much more faithfully than precise counts.
Constrain tone and register
The tone of the response directly influences its utility: text with the wrong tone is text you have to rewrite. Be explicit, even if it means stacking specifications: “Tone: professional but accessible. Avoid technical jargon unless unavoidable (in which case, define it). Use formal language. No emojis or informal language.”
Pro tip: the most effective tone directives often compare the task to a known professional situation. “Respond like a senior consultant presenting to an executive committee,” “Adopt a pedagogical tone, like a professor explaining to master’s students,” or “Be direct and concise, like an internal audit report”: each of these phrases condenses a whole set of vocabulary, length, and posture choices into one image that the model knows how to decode.
Constrain scope
Delimiting scope means telling the model where to stop. Here’s an example of constraints:
Scope constraints:
- Focus ONLY on the French market
- Do NOT mention US or UK regulations
- Ignore tax aspects (another expert handles this)
- If information is missing, state it explicitly
rather than inventing it
Pay close attention to the last constraint: it’s your best defense against hallucinations. A model asked for a complete answer tends to fill gaps with plausible information; by explicitly authorizing it to admit its limits, you turn silent invention into a visible flag that you can then handle.
Combine context and constraints
In practice, a professional prompt naturally combines everything above: context and permanent rules in the system prompt, data and expected format in the user message. Here’s a complete HR analysis example:
messages = [
{
"role": "system",
"content": """You are a senior HR analyst at a tech company.
Rules:
- Formal English, professional tone
- Base your analysis solely on the provided data
- If data is missing, flag it with [MISSING_DATA]
- Format: sections with headings, bullet points, no prose"""
},
{
"role": "user",
"content": """Analyze the absenteeism data below and propose an action plan.
Q1 2026 Data:
- Overall absenteeism rate: 7.2% (+1.8 points vs Q1 2025)
- Most affected department: Customer Support (12.1%)
- Main reason: short-term sick leave (< 5 days)
- Average tenure of absent employees: 2.3 years
Expected format:
1. Diagnosis (3 points max)
2. Probable causes (3 hypotheses)
3. Action plan (5 concrete measures with timeline)"""
}
]
Notice how every element covered in this lesson finds its place: role and register in the system, delimited data in the user message, numbered format at the end of the message, and the anti-invention guardrail ([MISSING_DATA]) set once and for all.
Key takeaways
- Context transforms a generic response into a personalized one
- Provide situational, document, and audience context as needed
- Always define the expected output format (JSON, list, table, etc.)
- Constrain length by structure rather than word count
- Delimit scope and authorize the model to signal missing information