Shadow policy evaluation is a testing technique where you run a new policy alongside your active policy without enforcing the new one. Both policies evaluate every tool call, but only the active policy's decision takes effect. The shadow policy's decisions are logged for comparison.
Changing safety policies in production is risky. A rule that is too permissive could allow harmful actions. A rule that is too restrictive could break agent functionality. Shadow evaluation lets you test changes against real production traffic before they take effect.
const guard = createGuard({
policy: activePolicy,
shadowPolicy: candidatePolicy,
});
const decision = guard('file.write', { path: '/tmp/output.csv' });
// decision.action is from the active policy (enforced)
// decision.shadow.action is from the candidate policy (logged only)
After running shadow evaluation for a period, analyze the differences:
If the shadow policy produces better results (fewer false positives, no new security gaps), promote it to active.
1. Write new policy
2. Deploy as shadow (shadow=true)
3. Run for 24-48 hours
4. Analyze differences
5. Adjust rules based on findings
6. Repeat steps 3-5 until satisfied
7. Promote to active
const guard = createGuard({
policy: loadYaml('./policies/active.yaml'),
shadowPolicy: loadYaml('./policies/candidate.yaml'),
onShadowDiff: (active, shadow, envelope) => {
metrics.increment('shadow.diff', {
tool: envelope.tool,
active: active.action,
shadow: shadow.action,
});
}
});
Shadow evaluation adds minimal overhead because the policy engine is synchronous and runs in microseconds. Evaluating two policies instead of one doubles the evaluation time, but microseconds doubled is still microseconds.
Explore more guides on AI agent safety, prompt injection, and building secure systems.
View All Guides