Prompt Engineering for Production AI Agents: Practices That Hold Up
The instructions given to an AI agent, its prompt, decide much of how accurate, safe and costly it is. A prompt edited casually can quietly break a working agent. Teams that treat prompts like code, with reviews, versions and tests, get agents that stay reliable.
The short answer: a production prompt is code. Write it with a clear goal, full context and a fixed structure, show examples, define the exact output, and tell the agent what to do when it is unsure. Then keep it in version control and test every change against a set of real cases before it ships. Our Agent Assurance team builds and tests prompts this way for agentic solutions.
Most prompt advice is written for one-off chats. An agent is different. It runs thousands of times, with inputs you never saw, and its answers trigger real actions. A prompt that works in a demo has to keep working on the ten-thousandth run.
Which prompt engineering practices hold up in production?
Ten practices hold up, in three groups: write the prompt clearly, show and shape the output, and run the prompt like code.
Write it clearly
- State the job and the reader. Say who the agent serves, what a good result looks like and why. Context about the purpose helps the model make better choices in cases you didn’t foresee.
- Give full context, once. Include the facts the agent needs: policies, product rules, definitions. Don’t make the model guess what “standard terms” means.
- Structure it. Separate instructions, context, examples and the user’s input into clearly marked sections. Anthropic’s prompt engineering guide recommends XML-style tags such as
<policy>and<examples>for Claude. - Say what to do, not only what to avoid. “Answer in three sentences or fewer” works better than “don’t be long-winded”.
Show and shape
- Show examples. Two to five varied examples of good inputs and outputs teach format and tone faster than paragraphs of rules. Include one tricky case.
- Define the output exactly. If another system reads the answer, give a schema: field names, types, allowed values. Validate the output in code and retry if it fails.
- Give it a way out. Tell the agent what to do when it is unsure or the answer isn’t in its sources: say so, ask a question, or hand over to a person. An agent with no way out will guess.
Run it like code
- Keep prompts in version control. Store them in the repository, review changes like code, and never edit a live prompt in a console. Version the prompt together with the model version it was tested on (see DevOps for AI Agents).
- Test every change on a golden set. A golden set is a few hundred real cases with agreed good answers. Run it after every prompt edit and model upgrade, several times each, because answers vary between runs. Release only if the scores hold. See How to Test AI Agents.
- Keep it lean. Every word in the prompt is paid for on every request. Remove rules that no test case needs, and move rarely used instructions into tools or documents the agent fetches only when needed.
The top six parts are trusted instructions; the user’s input sits last, clearly marked as data rather than orders.
How do prompts affect AI agent security?
Agents read text from users, documents and websites. Some of that text will try to give orders: “ignore your instructions and ...”. This is called prompt injection.
- Mark clearly which parts of the prompt are trusted instructions and which are untrusted data.
- Tell the agent that instructions inside documents or user content are data, not commands.
- Don’t rely on the prompt alone. Limit what the agent’s tools can do, and require a person’s approval for risky actions such as payments or deletions.
- Include injection attempts in your golden set, so every release is tested against them.
Why re-test the prompt when the model changes?
Prompts are tuned to a model. A new model version can follow instructions more literally, or less, and a prompt that was perfect can start to drift. Pin the exact model version in production, test new versions in the background against your golden set, and adjust the prompt before you switch.
A prompt change ships only when the golden-set scores hold, and every failure found in live use becomes a new test.
Common mistakes
- Fixing each new failure by adding another rule, until the prompt contradicts itself.
- Testing a prompt change on two or three examples.
- Editing prompts directly in production.
- Upgrading the model without re-running the tests.
- Trusting text from documents or users as if it were instructions.
How SHVX can help
Our Agent Assurance team reviews prompts, builds golden sets and sets up the tests that let you change prompts and models with confidence.
Learn more about Agent Assurance.
FAQ
What is prompt engineering?
Writing and testing the instructions an AI model follows, so its answers are accurate, consistent and in the right format.
How long should a production prompt be?
As long as it needs to be to pass your tests, and no longer. Every extra word costs money on every request.
Do prompts need version control?
Yes. A prompt change can alter an agent’s behaviour as much as a code change.
Will the same prompt work on a different model?
Often not exactly. Re-test on your golden set and adjust before switching models.
Prompting guidance checked against Anthropic’s documentation in November 2026.