Most AI workflow demos look impressive on day one. On day ten, an upstream API returns HTTP 500, a client uploads a corrupted PDF, or an incoming email contains text that tricks an agent into calling the wrong tool.
Prompt engineering cannot fix operational reliability. Three simple code patterns can.
1. Put a Code Gate in Front of Every External Action
When an AI agent can read untrusted input (emails, web pages, uploaded PDFs) and call tools that send messages, write database rows or trigger payments, instructions like "never send data to strangers" inside the system prompt are not a security boundary.
In our open-source tool-gated agent lab (tool-gated-ai-agent), every write or outbound call passes through a deterministic ToolGate:
if tool == "send_email": if to not in self.allow_recipients: self._audit(tool, args, "DENY", "recipient not in allow-list", ms) return {"ok": False, "blocked": True} if args.get("triggered_by_untrusted_input") and not args.get("human_confirmed"): self._audit(tool, args, "DENY", "human confirmation required", ms) return {"ok": False, "blocked": True} Every call—allowed, denied or failed—writes a structured JSONL entry with timestamp, arguments, decision and latency. When an upstream endpoint throws a transient HTTP 500, the wrapper retries with backoff; if it stays down, it returns a clean error instead of crashing the batch.
2. Hold High-Value Actions for a Human
In our multi-process business automation suite (ai-business-automation-suite), routine invoices below EUR 2,500 parse cleanly into CSV. Any invoice above the threshold routes automatically to human_approval_queue.json so a person approves before anything moves.
3. Catch Bad Inputs in a Dead-Letter Queue
Real-world data is messy: missing totals, broken email addresses, half-scanned PDFs. Instead of letting one malformed item halt a 100-item run, every validation failure appends a structured record to dead_letter.jsonl and the pipeline finishes the remaining valid items cleanly.
In our synthetic 3-workflow benchmark (10 invoices, 10 inbound leads, 3 weekly KPI sheets), both injected bad records landed cleanly in dead_letter.jsonl with zero crashes and 1.32 ms total execution time.
Want to check where your own AI app or workflow has blind spots?
- Free 2-minute browser self-check (no login): https://havendigital.pages.dev/check?utm_source=devto&utm_medium=article&utm_campaign=v5-gates
- All reproducible labs & demos: https://havendigital.pages.dev/proof?utm_source=devto&utm_medium=article&utm_campaign=v5-gates
- 48h Light Audit (€199 fixed, €0 if nothing is confirmed): https://ai-app-security.pages.dev/?utm_source=devto&utm_medium=article&utm_campaign=v5-gates


