Guardrail

What is a guardrail?

A guardrail is an eval that has been moved into the orchestration loop, so mistakes get caught and fixed before the output ever ships. Instead of only measuring an error after the fact, the same check runs while the agent works: the agent generates a first attempt, an auditor checks the work, and the auditor sends any errors it finds back to the agent to fix. Guardrails are one of the four tools for building reliable AI products, alongside prompt engineering, context engineering, and orchestration.

How is a guardrail different from an eval?

An eval measures how often an error happens. A guardrail catches the error at runtime and routes it back for fixing, so it never reaches the customer. In Teresa Torres's work on AI-generated opportunity solution trees, a code check that described each tree's shape started as an eval—it counted, among other things, how often a parent ended up with too many children. She moved that same check into the agent's audit step as a guardrail: the auditor flagged parents with too many children and sent them back to the agent to add sub-groupings.

Deterministic checks make especially cheap guardrails. Because the check is pure code, running it inside the loop adds no extra LLM-call cost.

When should you reach for a guardrail?

Reach for a guardrail when you've exhausted prompt changes—especially when two error categories trade off against each other. Teaching Teresa's agent to add sub-groupings led it to add poorly framed parents; teaching it to frame parents well made it reluctant to group at all. Rather than hunting for a perfect prompt balance, she optimized the prompts for well-framed parents and let the guardrail catch the missed groupings. With that setup, both error rates finally went down.

Related terms:

Learn more:

← Back to AI Glossary

Last Updated: September 16, 2026