# LangChain, CrewAI and LlamaIndex

Drop-in zn guards for popular Python agent frameworks.

Source: https://usezn.com/docs/integrations/frameworks/

The adapters ship with the Python package (`pip install zn-gate`) under `zn_gate.integrations`. They use local rules by default and the cloud model when `ZN_API_KEY` is set.

## LangChain and LangGraph

A callback handler checks prompts and tool inputs as the agent runs:

```python
from zn_gate.integrations import ZnGuardCallbackHandler

handler = ZnGuardCallbackHandler(raise_on_injection=True)
agent = initialize_agent(tools, llm, callbacks=[handler])
```

## CrewAI

Wrap a tool function so blocked calls return a fallback instead of executing:

```python
from zn_gate.integrations import guarded_tool

@guarded_tool(on_block="return", fallback="BLOCKED_BY_GUARD", mask_secrets=True)
def run_search(query: str):
    return search_api(query)
```

## LlamaIndex

Check a query before it reaches the index:

```python
from zn_gate.integrations import ZnLlamaGuard

guard = ZnLlamaGuard(raise_on_violation=True)
safe_query = guard.on_query_start(user_query)
```

Not using a framework? See the [SDK](https://usezn.com/docs/zn-gate/sdk/).
