Prompt optimization is equal parts craft and measurement. The techniques below improve reliability and cost - but only if you verify them with evaluation instead of vibes.

Techniques that work

  • Write a strong system message. Establish role, constraints, and output format up front. "You are an expert code reviewer" beats "help me with code."
  • Use variables instead of hard-coding. Templating a prompt ({{language}}, {{code}}) keeps one prompt reusable across many inputs and makes it testable.
  • Provide few-shot examples. Two or three input→output pairs do more to shape behavior than a paragraph of instructions.
  • Use chain-of-thought deliberately. Asking the model to reason step by step improves complex tasks but costs tokens - measure the trade-off.
  • Right-size the context. Too much irrelevant context raises cost and latency and can degrade quality. Trim aggressively.
A prompt in the Infere app. Messages, variables and model settings are saved with the prompt file in Git, with a Try panel beside it. Example data.

Optimize for tokens, not just quality

Prompt optimization isn't only about better answers - it's about cheaper ones. Trimming a bloated system prompt can cut response cost dramatically. Watch prompt tokens vs. completion tokens to spot waste. Infere's Logs show a request's tokens and cost, and Cost and usage splits model spend from protection checks, so you can see exactly where the money goes.

Measure every change

The only way to know a prompt is better is to score it. Run each variant in the Playground and compare what comes back:

  1. Try each variant in the Playground. Every message there is a real request, billed to a key and logged.
  2. Add the requests whose responses you want to a test set, freeze the version, and score it with your evaluators in a scoring run.
  3. Compare the two scoring runs with Compare with… and let a check gate the release to production.
Prompt optimization that isn't measured is just guesswork with extra steps.

The shape of a good prompt

# prompts/code-reviewer.pml - ordered messages, each with a role

# system message
You are an expert {{language}} code reviewer.
Analyze for bugs, security, performance, and best practices.
Be specific and provide improved snippets.

# user message
{{code}}

Next steps

Infere keeps each prompt in your repository as prompts/<name>.pml, gives you the Playground to try a variant, and scoring runs to verify each change against a frozen test set. Optimize with confidence - every tweak is measured before it ships.

Every optimization changes the token footprint - see the true cost of agentic coding for how output length and model choice affect the bottom line. For versioning and releasing prompt changes, read our guide to prompt management as code. To test prompts against live models before shipping, try our AI prompt playground.

Optimize prompts with evidence

Iterate and evaluate every prompt change against your quality bar.

Create an account → See Evaluators