Why Model-Agnostic Matters
If your agent is tied to one model, you are exposed to pricing changes, API outages, and capability gaps. Writing prompts that work across models gives you flexibility to switch.
The patterns below work reliably on Claude (Sonnet 4), GPT-4o, and Gemini 1.5 Pro without modification.
1. Role Anchoring
Start every system prompt with a single sentence defining the role and the user.
You are a code review agent for a TypeScript monorepo. The developer is working on backend services.All three models respond to role anchoring. Without it, each model defaults to a different generic persona that may not match your task.
2. Explicit Output Format
Name the format before describing the task.
Return JSON only. No markdown. No preamble.
Task: extract the key entities from this text.Stating the format first means the model knows the constraint before processing the input. Models that see the format at the end sometimes produce prose first and format second.
3. Constraint-First
List what you do not want before listing what you do want.
Do not: add unsolicited suggestions, use bullet points, mention that you are an AI.
Do: answer the question directly in 2-3 sentences.Constraints filter output more reliably than positive instructions. "Be concise" is vague. "Max 3 sentences. No preamble." is specific.
4. The One-Task Rule
One prompt, one task. Do not ask the model to research and summarize and format and send.
This applies across all three models. Multi-task prompts produce output that partially completes each task. Single-task prompts complete one thing well.
If you need multiple tasks, chain the prompts. The output of one becomes the input of the next.
5. Temperature Control
For deterministic tasks (JSON extraction, code review, classification), use temperature 0.
For generative tasks (writing, brainstorming, summarization), use temperature 0.5 to 0.7.
# deterministic
response = client.complete(prompt=prompt, temperature=0)
# generative
response = client.complete(prompt=prompt, temperature=0.6)All three providers support temperature. The effect is consistent across models: lower temperature means more predictable output, higher means more varied.
What Does Not Transfer
A few patterns are provider-specific: Anthropic's extended thinking tags, OpenAI's structured output mode (which forces schema validation at the API level), and Gemini's multimodal input format. Keep these in provider-specific wrappers, not in your core prompt templates.
Comments (0)