# How do you catch an AI agent's hallucinated shell command before it runs?

Check the command statically before it executes. In a preprint on pre-action verification, a verifier that tests syntax, binary existence, and flags against the tool's own help text flagged 95.8% of invalid shell commands, at a 10.0% false-positive rate on valid ones.

The first two checks are exact. `bash -n` rejects malformed syntax and `which` rejects a binary that isn't installed. On the benchmark's complete commands they produced zero false positives, but they catch only half of the errors. The flag check catches the rest and causes every false alarm, all real flags the help-text parser missed. Flag doubts become non-blocking warnings. The authors caution that `bash -n` rejects incomplete fragments and `which` misses aliases, shell functions, and a session-updated PATH, so a deployed gate should treat those as abstentions.

A hallucinated flag can fail loudly, or run and do something unintended, a [silent failure](/answers/silent-failures/what-is-a-silent-failure-in-an-ai-agent).

The limit is the benchmark: its 9,930 commands over 482 tools are valid commands from the tldr corpus plus mutated invalid ones, not commands real agents produced, so 95.8% measures the check and not how often agents hallucinate. It's also a single-author preprint.

---

Published: 2026-11-04

Sources:
- Look Before You Leap: Pre-Action Verification for LLM Agents (arXiv:2609.11957): https://arxiv.org/abs/2609.11957 (fetched 2026-11-05)

Source: https://tessary.ai/answers/hallucinations/how-do-you-catch-a-hallucinated-shell-command-before-it-runs
More on Hallucinations: https://tessary.ai/answers/hallucinations
From Tessary, agent reliability for AI agents in production: https://tessary.ai
