Skip to main content

Deterministic governance middleware for LangChain agents — policy enforcement, cost limits, tool allowlisting, NHI scope controls, and SARIF audit evidence. No LLM in the governance path.

Project description

langchain-tealtiger

Deterministic governance middleware for LangChain agents. Policy enforcement, cost limits, tool allowlisting, and audit evidence — no LLM in the governance path.

PyPI License Python

Installation

pip install langchain-tealtiger

Quick Start

from langchain.agents import create_agent
from langchain_tealtiger import TealTigerMiddleware

agent = create_agent(
    model="claude-sonnet-4-6",
    tools=[search, calculator, file_write],
    middleware=[
        TealTigerMiddleware(
            policies=[
                {"type": "tool_allowlist", "tools": ["search", "calculator"]},
                {"type": "cost_limit", "max_per_session": 5.00},
                {"type": "rate_limit", "max_calls": 100, "window": "1h"},
            ],
            freeze_tools=["rm_rf", "drop_database"],
        )
    ],
)

That's it. Every tool call now goes through deterministic governance evaluation before execution.

How It Works

TealTiger middleware hooks into LangChain's agent loop:

Hook What happens
before_agent Initialize governance session
wrap_tool_call Evaluate policies before every tool call → ALLOW / DENY
after_model Optional PII detection on model output
after_agent Finalize evidence trail
User → Agent → Model → Tool Call → [TealTiger: ALLOW?] → Execute Tool
                                   └── [DENY] → Return denial message

Policy Types

Tool Allowlist

Only permit specific tools:

{"type": "tool_allowlist", "tools": ["search", "calculator", "read_file"]}

Tool Blocklist

Block specific dangerous tools:

{"type": "tool_blocklist", "tools": ["delete_file", "execute_sql"]}

Cost Limits

Cap spending per session or per request:

{"type": "cost_limit", "max_per_session": 5.00, "max_per_request": 0.50}

Rate Limits

Limit tool call frequency:

{"type": "rate_limit", "max_calls": 100, "window": "1h"}

FREEZE Rules

Immutable deny rules — always enforced regardless of governance mode:

TealTigerMiddleware(
    freeze_tools=["rm_rf", "drop_database", "format_disk"],
)

Governance Modes

Mode Behavior Use case
ENFORCE Block denied actions Production
MONITOR Allow all, log violations Staging / testing
REPORT_ONLY Allow all, generate reports Initial rollout
# Start in MONITOR mode to observe, then switch to ENFORCE
TealTigerMiddleware(policies=[...], mode="MONITOR")

Accessing Governance Evidence

After agent execution, access the full decision trail:

middleware = TealTigerMiddleware(policies=[...])
agent = create_agent(model="...", tools=[...], middleware=[middleware])

result = agent.invoke({"messages": [HumanMessage("...")]})

# Session summary
print(middleware.summary)
# SessionSummary(total_evaluations=8, allowed=7, denied=1, session_cost=2.34)

# Full evidence trail
for decision in middleware.evidence:
    print(f"{decision.tool_name}: {decision.action} ({decision.reason})")

Each decision includes:

  • Correlation ID (UUID) for tracing
  • Evaluation time (<5ms typical)
  • Triggered policies
  • Risk score (0-100)
  • Reason codes

Use with LangGraph

Works seamlessly when agents are composed into LangGraph workflows:

from langgraph.graph import START, StateGraph
from langchain.agents import AgentState, create_agent

governed_agent = create_agent(
    model="claude-sonnet-4-6",
    tools=[...],
    middleware=[TealTigerMiddleware(policies=[...])],
)

graph = (
    StateGraph(AgentState)
    .add_node("agent", governed_agent)
    .add_edge(START, "agent")
    .compile()
)

Key Properties

  • Deterministic: No LLM in the governance path. Same input → same decision, every time.
  • Fast: <5ms evaluation latency per tool call.
  • Auditable: Full evidence trail with correlation IDs for compliance.
  • Graph-native: Visible in LangSmith traces, works with LangGraph checkpointing.
  • Composable: Drop into any agent, works with subgraphs.

Related

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_tealtiger-0.1.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_tealtiger-0.1.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_tealtiger-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_tealtiger-0.1.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for langchain_tealtiger-0.1.0.tar.gz
Algorithm Hash digest
SHA256 15a86480e4ee097b1be6f701e13a12ec35932747fb9db255cb986a5ae6149309
MD5 fbf2a7ec4585ec46be6a4e731a2b16f8
BLAKE2b-256 6aa54394a6645b1615a2b50f40f758a211358e3afae15afbaecde6a8b039b275

See more details on using hashes here.

File details

Details for the file langchain_tealtiger-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_tealtiger-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41d729daca2b054dd975e701aa253dfc7ca55338982876a97ec1039166504365
MD5 e5659fd8c286a233d2ee83db7245a039
BLAKE2b-256 cade952ad94d34daf4b89cc0cb46d8b0744334a3417ce33c6900fddcbff53e6c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page