Time to Magic < 60 Seconds

The Transactional
Firewall for
AI Agents

Build reliable, production-ready AI agents in 5 lines of code. Stop LLM hallucinations from corrupting your state with automated rollbacks and invariants.

View the Cookbook
GitHub starsTrusted by developers worldwide
agent_memory.py
1# Without StateGuard
2app.invoke({'action': 'charge', 'amount': 500})
3# > [SAVED: Agent hallucinates, user charged $500]
4# With StateGuard
5with checkpointer.transaction():
6 app.invoke({'action': 'charge', 'amount': 500})
7# > [BLOCKED: ValueError - Negative Balance]
8# > [ACTION: Memory Rolled Back to Safe State]

The Problem with Agent Memory

If you don't validate state, one hallucination will corrupt your entire workflow.

The Problem

Agents are probabilistic. Even the best models eventually output bad JSON or take illegal actions (like booking a negative number of hotel days). Native checkpointers blindly save this corrupted state to your database, permanently breaking the graph.

The StateGuard Solution

StateGuard acts as a firewall. It intercepts the memory save. If a business rule fails, it blocks the database write, safely rolls the memory back to the last pristine state, and automatically executes Saga compensations (like refunding a Stripe charge) to clean up real-world side effects.

StateGuard Terminal Demo intercepting a hallucination

We don't replace your memory.
We put a bulletproof vest on it.

StateGuard requires zero refactoring. It is not a new framework that forces you to rewrite your logic. Simply wrap your existing Python dictionaries or drop us in as your LangGraph checkpointer.

The 60-Second Cookbook

Integrate StateGuard into your stack instantly.

1from stateguard import StateGuardCheckpointer
2from langgraph.graph import StateGraph
3
4# 1. Keep your existing LangGraph code
5workflow = StateGraph(AgentState)
6workflow.add_node('agent', call_agent)
7
8# 2. Drop in the checkpointer with your invariants
9checkpointer = StateGuardCheckpointer(
10 invariants=[no_negative_balance],
11 compensations={'stripe_refund': refund_logic}
12)
13
14app = workflow.compile(checkpointer=checkpointer)

Visualizing the Intercept

Watch how StateGuard catches hallucinations before they hit the database.

Agent 1
Standard Generation
Agent 2 (Hallucinates)
Bad JSON payload
StateGuard Firewall
Intercepts & Rolls Back

Robust State Management

Stop treating your LLM agent memory like a plain text file.

TypeScript for your Agent's Memory

Define strict rules (invariants) for your agent's state. If a generation violates a rule, StateGuard blocks it instantly.

Database Transactions for AI

Wrap LangGraph nodes in transactional blocks. Either the entire multi-step process succeeds, or the state safely rolls back.

An Undo Button for API Calls

Automatically trigger rollback logic to undo side-effects (like refunding a Stripe charge) when an agent hallucinates.

Works with your stack

Drop-in compatibility with the most popular multi-agent frameworks.

"Doesn't LangGraph already do this?"

LangGraph Native Memory

  • Saves corrupted data permanently.
  • Manual rollbacks required.
VS

StateGuard Memory

  • Blocks corrupted data instantly.
  • Automated API rollbacks via Sagas.

Frequently Asked Questions

Everything you need to know before putting StateGuard into production.

Does this add latency to my LLM calls?
No. StateGuard operates purely locally on your graph's state object in memory before it is persisted. The overhead for invariant checking and transaction routing is typically <1ms.
Do I need to rewrite my LangGraph code?
Absolutely not. StateGuard is designed as a drop-in replacement for native checkpointers like MemorySaver or SqliteSaver. You only need to change 2 lines of code.
What if I use custom Python classes for my state?
StateGuard natively supports Pydantic models, TypedDicts, and custom Python classes out of the box. Your invariants can be simple functions or complex validation logic.
Is there an Enterprise version?
The core library is 100% open-source and free for local/self-hosted use. We are currently building StateGuard Cloud, which will offer visual dashboards, anomaly detection, and fleet-wide rollback analytics.