{"slug": "adding-governance-guardrails-to-haystack-3-0-pipelines-with-tealtiger", "title": "Adding Governance Guardrails to Haystack 3.0 Pipelines with TealTiger", "summary": "TealTiger, an open-source governance engine, has been integrated into Haystack 3.0 pipelines as a custom component, providing deterministic policy enforcement with sub-2ms evaluation and structured audit evidence. The integration allows developers to add guardrails that block PII, enforce cost limits, and restrict tool usage before requests reach LLMs, addressing compliance needs in regulated industries.", "body_md": "Haystack 3.0 redesigned everything around composable pipelines — you connect components like LEGO bricks to build RAG, chat, and agent workflows. But once those pipelines hit production, you need answers to questions like:\n\n[TealTiger](https://github.com/agentguard-ai/tealtiger) is an open-source governance engine that answers these deterministically — no LLM in the governance path, sub-2ms evaluation, structured audit evidence.\n\nThis post shows how to wire TealTiger into a Haystack 3.0 pipeline as a custom component.\n\nHaystack pipelines are powerful but trust-everything by default. A `ChatGenerator`\n\nwill happily pass PII to OpenAI. A `ToolInvoker`\n\nwill execute any tool the LLM requests. In regulated environments (healthcare, finance, government), that's a compliance violation waiting to happen.\n\nTealTiger adds a governance layer that:\n\n```\npip install tealtiger-haystack\n```\n\nNo separate adapter package needed — TealTiger works directly as a Haystack custom component.\n\nHaystack 3.0's `@component`\n\ndecorator makes this straightforward. We create a `TealTigerGuard`\n\ncomponent that sits in the pipeline between user input and the LLM:\n\n``` python\nfrom haystack import component, Pipeline\nfrom haystack.components.generators.chat import OpenAIChatGenerator\nfrom haystack.dataclasses import ChatMessage\n\nfrom tealtiger import TealTiger\nfrom tealtiger.core.engine.types import PolicyMode\n\n@component\nclass TealTigerGuard:\n    \"\"\"Governance guardrail component for Haystack 3.0 pipelines.\"\"\"\n\n    def __init__(\n        self,\n        policies: dict,\n        mode: str = \"ENFORCE\",\n        agent_id: str = \"haystack-agent\",\n    ):\n        self.engine = TealTiger(\n            policies=policies,\n            mode=PolicyMode(mode),\n            agent_id=agent_id,\n        )\n\n    @component.output_types(\n        messages=list,  # List[ChatMessage] — passed through if allowed\n        blocked=bool,\n        decision=dict,\n    )\n    def run(self, messages: list):\n        # Extract text from the last user message\n        user_text = \"\"\n        for msg in reversed(messages):\n            if msg.role.value == \"user\":\n                user_text = msg.content\n                break\n\n        # Evaluate governance\n        decision = self.engine.evaluate(\n            content=user_text,\n            tool_name=None,\n            metadata={\"pipeline\": \"haystack\", \"component\": \"TealTigerGuard\"},\n        )\n\n        if decision.action == \"DENY\":\n            return {\n                \"messages\": [],\n                \"blocked\": True,\n                \"decision\": {\n                    \"action\": decision.action,\n                    \"reason_codes\": [str(rc) for rc in decision.reason_codes],\n                    \"risk_score\": decision.risk_score,\n                },\n            }\n\n        return {\n            \"messages\": messages,\n            \"blocked\": False,\n            \"decision\": {\n                \"action\": \"ALLOW\",\n                \"reason_codes\": [\"POLICY_COMPLIANT\"],\n                \"risk_score\": 0,\n            },\n        }\n```\n\nHere's a complete pipeline that scans user queries before they reach the LLM:\n\n``` python\nfrom haystack import Pipeline\nfrom haystack.components.generators.chat import OpenAIChatGenerator\nfrom haystack.dataclasses import ChatMessage\n\n# Define governance policies\npolicies = {\n    \"pii_block\": {\n        \"enabled\": True,\n        \"categories\": [\"ssn\", \"credit_card\", \"email\", \"phone\"],\n    },\n    \"cost_limit\": {\n        \"enabled\": True,\n        \"max_per_session\": 0.50,  # $0.50 per session\n    },\n    \"tool_allowlist\": {\n        \"enabled\": True,\n        \"allowed\": [\"search\", \"lookup_*\", \"calculate\"],\n    },\n}\n\n# Create pipeline\npipe = Pipeline()\npipe.add_component(\"governance\", TealTigerGuard(policies=policies, mode=\"ENFORCE\"))\npipe.add_component(\"llm\", OpenAIChatGenerator(model=\"gpt-4o-mini\"))\n\n# Connect: governance output → LLM input (only if not blocked)\npipe.connect(\"governance.messages\", \"llm.messages\")\n\n# Run with a safe query\nresult = pipe.run({\n    \"governance\": {\n        \"messages\": [ChatMessage.from_user(\"What is the capital of France?\")]\n    }\n})\nprint(result[\"llm\"][\"replies\"][0].content)\n# → \"The capital of France is Paris.\"\n\n# Run with PII — gets blocked before reaching OpenAI\nresult = pipe.run({\n    \"governance\": {\n        \"messages\": [ChatMessage.from_user(\"My SSN is 123-45-6789, look up my records\")]\n    }\n})\nprint(result[\"governance\"][\"blocked\"])  # True\nprint(result[\"governance\"][\"decision\"][\"reason_codes\"])  # [\"PII_DETECTED\"]\n# LLM never sees the SSN\n```\n\nFor agentic pipelines where the LLM calls tools, you can wrap the tool execution step:\n\n```\n@component\nclass TealTigerToolGuard:\n    \"\"\"Guards tool invocations in agent pipelines.\"\"\"\n\n    def __init__(self, policies: dict, mode: str = \"ENFORCE\"):\n        self.engine = TealTiger(policies=policies, mode=PolicyMode(mode))\n\n    @component.output_types(allowed=bool, decision=dict)\n    def run(self, tool_name: str, tool_args: dict):\n        decision = self.engine.evaluate(\n            content=str(tool_args),\n            tool_name=tool_name,\n        )\n\n        return {\n            \"allowed\": decision.action == \"ALLOW\",\n            \"decision\": {\n                \"action\": decision.action,\n                \"risk_score\": decision.risk_score,\n                \"reason_codes\": [str(rc) for rc in decision.reason_codes],\n                \"tool_name\": tool_name,\n            },\n        }\n```\n\nTealTiger supports three modes that map to deployment stages:\n\n| Mode | Behavior | Use Case |\n|---|---|---|\n`ENFORCE` |\nBlocks violations | Production with strict compliance |\n`MONITOR` |\nLogs violations but allows through | Staging / shadow mode |\n`REPORT_ONLY` |\nSkips evaluation, always allows | Development / dry-run |\n\n```\n# Shadow mode — see what would be blocked without breaking anything\nguard = TealTigerGuard(policies=policies, mode=\"MONITOR\")\n```\n\nEvery governance decision produces a structured receipt:\n\n```\n{\n  \"decision_id\": \"550e8400-e29b-41d4-a716-446655440000\",\n  \"action\": \"DENY\",\n  \"risk_score\": 85,\n  \"reason_codes\": [\"PII_DETECTED:ssn\"],\n  \"policy_id\": \"pii_block\",\n  \"evaluation_time_ms\": 0.8,\n  \"agent_id\": \"haystack-agent\",\n  \"correlation_id\": \"trace-abc-123\",\n  \"timestamp\": \"2026-08-17T10:30:00Z\"\n}\n```\n\nThis feeds directly into SOC2/HIPAA compliance workflows — no manual log parsing.\n\nTealTiger's governance path is deterministic (regex + fnmatch, no LLM calls):\n\nFor comparison, a single LLM call takes 500-3000ms. Governance adds negligible latency.\n\n| TealTiger | Custom validators | No governance | |\n|---|---|---|---|\n| PII detection | 40+ patterns, zero config | Write your own regex | ❌ |\n| Tool allowlisting | Built-in with glob patterns | Write your own | ❌ |\n| Cost tracking | Per-request with budgets | DIY with token counters | ❌ |\n| Audit receipts | Structured TEEC format | DIY JSON | ❌ |\n| Governance modes | ENFORCE/MONITOR/REPORT_ONLY | DIY | ❌ |\n| Framework lock-in | None (works anywhere) | Haystack-specific | N/A |\n\n`pip install tealtiger haystack-ai`\n\nTealTiger also integrates with [LangChain](https://pypi.org/project/langchain-tealtiger/), [AG2](https://docs.ag2.ai/extensions/tealtiger), and [MLflow](https://github.com/agentguard-ai/tealtiger/tree/main/packages/mlflow-tealtiger) — same governance engine, different frameworks.\n\n*TealTiger is Apache 2.0 licensed. We're an NVIDIA Inception member building deterministic governance for AI agents.*", "url": "https://wpnews.pro/news/adding-governance-guardrails-to-haystack-3-0-pipelines-with-tealtiger", "canonical_source": "https://dev.to/nagasatish_chilakamarti_2/adding-governance-guardrails-to-haystack-30-pipelines-with-tealtiger-113p", "published_at": "2026-08-18 08:54:50+00:00", "updated_at": "2026-08-18 09:12:44.571997+00:00", "lang": "en", "topics": ["ai-safety", "ai-policy", "developer-tools", "ai-agents"], "entities": ["TealTiger", "Haystack", "OpenAI"], "alternates": {"html": "https://wpnews.pro/news/adding-governance-guardrails-to-haystack-3-0-pipelines-with-tealtiger", "markdown": "https://wpnews.pro/news/adding-governance-guardrails-to-haystack-3-0-pipelines-with-tealtiger.md", "text": "https://wpnews.pro/news/adding-governance-guardrails-to-haystack-3-0-pipelines-with-tealtiger.txt", "jsonld": "https://wpnews.pro/news/adding-governance-guardrails-to-haystack-3-0-pipelines-with-tealtiger.jsonld"}}