Save money using LLMs with Circuit Breaker
By u/hamansharma · · Concepts
In normal software, failures are obvious—like crashes or timeouts. But with AI, failures are often hidden because the system still produces an answer that looks correct but is actually wrong (like hallucinated facts or fake citations). This makes AI failures harder to detect and more dangerous, since everything appears to be working even when it isn’t.
Instead of just “working” or “broken,” systems should have a middle “degraded” state where they limit risky behavior or fall back to simpler methods. It also recommends monitoring different types of failures (not just crashes), using repeated checks before trusting the system again, and tracking an overall “health score” of the AI. The key idea is that AI reliability requires smarter monitoring and gradual safeguards, because problems aren’t always obvious.
In a real system, instead of shutting everything down when something looks off, you can move into a “degraded mode.” For example, if your AI agent starts giving inconsistent or low-confidence answers, you could:
- Switch to a simpler or more reliable model
- Turn off risky tools (like web browsing or autonomous actions)
- Ask for human review before final output
This way, your system still works—but in a safer, more controlled way instead of fully breaking.
Another example is detecting different types of failures beyond crashes. You can add checks like:
- Structure check: Is the output valid JSON or in the expected format?
- Sanity check: Does the answer contradict known facts or inputs?
- Behavior check: Is the agent stuck in a loop or making too many tool calls?
- Hallucination check: Use another LLM (or rules) to verify the answer
If any of these fail repeatedly, your circuit breaker can trigger and limit or stop the system.
Additionally, you can use a “health score” system instead of a simple pass/fail. For example:
- Start with a score of 1.0 (fully healthy)
- Reduce the score when failures happen (bad format, hallucination, etc.)
Define thresholds:
- 0.8 → normal
- 0.5 → degraded mode
- 0.2 → shut down or fallback
This gives you a more realistic view of how your AI is performing over time.
Finally, instead of trusting a single success to recover the system, require multiple successful runs before restoring full access. For example:
- After failure, run 5–10 test prompts
- Only return to normal mode if most pass: This prevents the system from flipping between “working” and “broken” too quickly.
Put together, these examples show how to build a smarter circuit breaker: limit risk instead of just stopping, monitor quality (not just errors), and recover gradually instead of instantly.