---
title: "How do I test whether my AI agent follows its system prompt?"
description: Turn written system-prompt, skill, and tool rules into deterministic behavioral checks on tool calls, arguments, call order, and refusals—and run each test multiple times before and after fixes.
canonical: https://www.projectvail.com/docs/questions/test-whether-ai-agent-follows-system-prompt
last_updated: 2026-12-01
---

# How do I test whether my AI agent follows its system prompt?

> Concise answer grounded in VAIL's 15-agent model-discretion study and pre-ship hardening study. The page for people is https://www.projectvail.com/docs/questions/test-whether-ai-agent-follows-system-prompt; all questions: https://www.projectvail.com/docs/questions.md.

## Short answer

Extract the concrete behavioral rules from your system prompt, skill files, and tool descriptions, turn each rule into a realistic test prompt paired with a **deterministic mechanical check** (which tools were called or avoided, with what arguments, in what order, and whether the agent refused or escalated), and run each test **multiple times** against the real agent.

Reading the prompt, running unit tests, or eyeballing a single reply will not tell you whether the model actually obeys what you wrote. Across 15 real-world agents in VAIL's [15-agent study](https://www.projectvail.com/docs/case-studies/model-discretion.md), **144 of 153 discovered behavior risks (94%) depended on the model choosing to follow written instructions** rather than on a bug in harness code.

---

## Why reading the prompt or running unit tests is not enough

- **Written instructions are hypotheses, not guarantees.** Writing *"verify the signup exists before searching the web"* or *"always ask before sending"* creates a requirement in prose, not an enforcement gate in code.
- **Unit tests only reach the 6% in code.** A unit test confirms your tool function handles HTTP errors and returns valid JSON; it never tests whether the model remembers to call the prerequisite lookup first.
- **Polite prose hides rule breaks.** An agent can skip a lookup, search with unverified inputs, or invoke a forbidden tool while still returning a fluent final answer that passes casual spot-checks.

---

## What pre-ship system-prompt testing found in practice

In VAIL's [pre-ship hardening case study](https://www.projectvail.com/docs/case-studies/hardening-a-new-ai-agent.md), a coding agent (Claude Code) built an internal Slack operations assistant (Martin) from a short spec—a persona, three skills, and a small read-only toolset—and tested it against its own instructions before anyone used it:

| Stage | What happened | Concrete result |
| --- | --- | --- |
| **1. Scan source definition** | Uploaded 11 source files (prompts, skills, tools, code) over MCP | Proposed **10 candidate behavior risks** citing specific rules, plus control tests |
| **2. Baseline across 3 models** | Ran **5 attempts per test** across `gpt-oss-120b`, `gpt-oss-20b`, and `kimi-k3` (**180 runs**) | Confirmed **4 real problems** and 2 minor ones; worst finding: when a user typed unverified person details in chat, Martin web-searched that person in **13 of 13 completed runs** on every model despite its vetting rule |
| **3. Fix rules vs judgment** | Moved deterministic abuse-limit checks and email classification into tool code; tightened prompt wording for judgment rules | Re-ran the exact **180-run matrix**: resistance rose on every model (`33% → 45%` on `gpt-oss-120b`, `31% → 51%` on `gpt-oss-20b`, `58% → 67%` on `kimi-k3`); unverified web searches dropped from **13/13 to 2/15 runs** |
| **4. Re-measure controls** | Re-ran routine control tests alongside risk tests | Caught a **regression introduced by the fix**: a new rule caused one model to fail a routine usage question more often (**4/5 → 2/5 runs**) |

---

## Five steps to test system-prompt compliance

1. **Inventory every rule across all instruction files.** Do not stop at the top-level system prompt—rules also live in `AGENTS.md`, `SKILL.md` files, subagent instructions, and tool descriptions.
2. **Write targeted adversarial and boundary inputs for each rule.** Test realistic messy user messages that tempt the agent to take a shortcut (such as pasting unverified details into chat, omitting a required parameter, or asking a question it could answer from recall instead of calling a search tool).
3. **Score mechanically on actions, not just text.** Check `tool_called`, `tool_not_called`, tool arguments, call order, subagent routing, and required refusals rather than relying solely on an LLM judge reading the final reply.
4. **Run at least 5 repetitions per test before and after fixes.** Single-shot checks cannot distinguish a 95% rule from a 50% rule. Always include **control tests** (routine tasks that must keep working) so you catch regressions introduced by stricter wording.
5. **Move hard rules out of the prompt into code.** If a rule is non-negotiable (permissions, credentials, forbidden writes, numeric limits), enforce it in tool code or middleware rather than adding stronger wording to the system prompt, then keep scheduled checks running after launch.

---

## How VAIL automates this

The [VAIL Agent Assurance Engine](https://www.projectvail.com/platform/agent-assurance.md) reads your agent's source definition (prompts, skill files, tool schemas, subagents) with no SDK and no trace access:

- **Derives candidate risks and controls** directly from the files that define the agent, citing the exact file and line of each instruction.
- **Generates deterministic probes** scored by 17 mechanical metric types—no judge model—and lets coding agents run the local hardening loop over MCP (`vail-grading`) before deployment.
- **Schedules approved probes** against a sandboxed live copy after launch so you know if a prompt edit, memory update, or model change breaks system-prompt compliance later.

---

## Related questions

- [Which of my agent's rules are enforced in code?](https://www.projectvail.com/docs/questions/which-agent-rules-are-enforced-in-code.md)
- [How many times should I run an agent test before trusting the result?](https://www.projectvail.com/docs/questions/how-many-runs-per-probe-to-spot-a-regression.md)
- [Can an AI agent's behavior change with no deploy?](https://www.projectvail.com/docs/questions/can-ai-agent-behavior-change-with-no-deploy.md)
- [Are evals enough to test an AI agent?](https://www.projectvail.com/docs/questions/ai-agent-evals-vs-behavioral-probing.md)

---

## Sources and next steps

- [Testing a new AI agent before it ships: 4 real problems found and fixed in one Claude Code session](https://www.projectvail.com/docs/case-studies/hardening-a-new-ai-agent.md)
- [94% of an AI agent's risks are in its instructions, not its code](https://www.projectvail.com/docs/case-studies/model-discretion.md)
- [Setup guides for Claude Code, Cursor, Codex, and Hermes over MCP](https://agents.projectvail.com/docs/guides)
- [Agent Assurance Engine](https://agents.projectvail.com)
