Metadata-Version: 2.4
Name: noma-langchain-integration
Version: 0.1.1
Summary: Noma guardrail middleware integration for LangChain
Project-URL: Homepage, https://github.com/Noma-Security/langchain-noma-integration-package
Project-URL: Source, https://github.com/Noma-Security/langchain-noma-integration-package
Project-URL: Issues, https://github.com/Noma-Security/langchain-noma-integration-package/issues
Author: Noma Security
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.10
Requires-Dist: httpx>=0.27.0
Requires-Dist: langchain<2.0.0,>=1.0.0
Description-Content-Type: text/markdown

# noma-langchain-integration

Noma guardrail middleware for LangChain agents. Scans user and assistant messages to detect and handle unsafe content before and after agent execution.

## Installation

```bash
pip install noma-langchain-integration
```

## Quick start

```python
from langchain.agents import create_agent
from langchain_noma.middleware import NomaGuardrailMiddleware

middleware = NomaGuardrailMiddleware(
    api_key="noma-...",  # or set NOMA_API_KEY env var
)

agent = create_agent(
    model="openai:gpt-4.1",
    tools=[...],
    middleware=[middleware],
)
```

The middleware runs two hooks automatically:

- **`before_agent`** — scans user messages before the agent processes them.
- **`after_agent`** — scans assistant messages after the agent responds.

Both sync and async hooks are supported (`abefore_agent`, `aafter_agent`).

## Configuration

All parameters are optional and keyword-only:

| Parameter | Type | Default | Description |
|---|---|---|---|
| `api_key` | `str \| None` | `NOMA_API_KEY` env | API key for the Noma service. Required when using the Noma SaaS endpoint. |
| `application_id` | `str \| None` | `NOMA_APPLICATION_ID` env or `"langchain"` | Application identifier sent with each scan request. |
| `block_failures` | `bool` | `True` | When `True` (fail-closed), block requests if the AIDR API is unreachable. When `False` (fail-open), allow requests through on scan failure. |

## Environment variables

| Variable | Required | Description |
|---|---|---|
| `NOMA_API_KEY` | Yes (SaaS) | API key. Can also be passed via the `api_key` constructor parameter. |
| `NOMA_APPLICATION_ID` | No | Override the application identifier (defaults to `"langchain"`). |
