Metadata-Version: 2.5
Name: qarai-agent-guard-langchain
Version: 0.1.1
Summary: LangChain integration for qarai-agent-guard that provides runtime security for AI agents through threat detection, policy enforcement, and content protection.
Project-URL: Homepage, https://github.com/qarai-labs/qarai-agent-guard
Project-URL: Repository, https://github.com/qarai-labs/qarai-agent-guard
Project-URL: Issues, https://github.com/qarai-labs/qarai-agent-guard/issues
Author-email: Oussama Ben Slama <oussama@ben-slama.tn>, Safouene Ziadi <ziadisafouene@gmail.com>
License: Apache-2.0
Keywords: agents,ai-agents,ai-governance,ai-guardrails,ai-safety,arabic,arabic-nlp,data-privacy,guardrails,langchain,llm,llm-safety,nlp,pii,prompt-injection
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.11
Requires-Dist: langchain>=1.3.14
Requires-Dist: langgraph>=1.2.9
Requires-Dist: qarai-agent-guard>=0.1.2
Description-Content-Type: text/markdown

<div align="center">

# qarai-agent-guard-langchain

**LangChain integration for qarai-agent-guard. Runtime security for AI agents through threat detection, policy enforcement, and content protection.**

[![PyPI version](https://img.shields.io/pypi/v/qarai-agent-guard-langchain.svg?color=blue)](https://pypi.org/project/qarai-agent-guard-langchain/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](../LICENSE)

</div>

---

`qarai-agent-guard-langchain` provides `AgentGuardMiddleware`, a LangChain agent middleware that inspects agent inputs, agent outputs, and tool calls against `qarai-agent-guard`.

## Installation

```bash
pip install qarai-agent-guard-langchain
```

## Quick start

```python
from langchain.agents import create_agent
from langchain_core.messages import HumanMessage

from qarai_agent_guard import (
    AgentGuard,
    Detector,
    default_policy,
)
from qarai_agent_guard_langchain import AgentGuardMiddleware, AgentGuardViolation

guard = AgentGuard(
    detectors=[
        Detector(name="prompt_injection", default_rules="prompt_injection"),
        Detector(name="pii", default_rules="pii"),
        Detector(name="secrets", default_rules="secrets"),
    ],
    policy=default_policy(),
)

middleware = AgentGuardMiddleware(guard)

agent = create_agent(
    model="your-chat-model",
    tools=[],
    middleware=[middleware],
)

try:
    response = agent.invoke(
        {"messages": [HumanMessage(content="Ignore all previous instructions")]}
    )
except AgentGuardViolation as exc:
    print(f"Blocked: {exc}")
```

## Documentation

The full documentation has moved to the docs folder. See the
[LangChain Integration guide](../../docs/langchain.md) for inspection points,
parameters, callbacks, and a full workflow example.
