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
pip install noma-langchain-integration
Quick start
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 these hooks automatically:
before_agent— scans user messages before the agent processes them.wrap_tool_call— scans each tool call's arguments before the tool runs, and its output before the model sees it.after_agent— scans assistant messages after the agent responds.
| Content | Block | Mask |
|---|---|---|
| User prompt | Before the model runs | Before the model runs |
| Tool call arguments | Tool is not run; the model gets an error tool message | Tool runs with masked arguments |
| Tool output | Replaced with an error tool message | Replaced with masked output |
| Final response | Replaced with a block message | Replaced with masked text |
Both sync and async hooks are supported (abefore_agent, awrap_tool_call, aafter_agent).
Tool scanning needs a Noma broker that supports the before_tool/after_tool phases. An older broker rejects them; tool calls then run unscanned (as in 0.1.x) and after_agent still scans the final response.
Streaming: response tokens (including tool-call arguments the model generates) stream before after_agent runs, so they are not blocked or masked in the stream; only the final state is. Use invoke/ainvoke when output must not reach users unscanned. Tool output is scanned before it is emitted.
Scans also send the agent's available tools (name, description and parameters, in OpenAI tool format), taken from the tools bound to the model call and kept in the run's own agent state, so parallel runs never mix them up. A run's first before_agent scan goes out without them, since no model call has happened yet; with a checkpointer, later turns of a conversation include them from the start. Requires langchain>=1.2.9; on older versions scans are sent without tools.
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"). |
Metadata
Release files for noma-langchain-integration 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| noma_langchain_integration-0.2.0.tar.gz | 101.1 kB | With provenance | Details for noma_langchain_integration-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| noma_langchain_integration-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for noma_langchain_integration-0.2.0-py3-none-any.whl |
Total release size: 110.1 kB
Release files / noma_langchain_integration-0.2.0.tar.gz
| Download URL | noma_langchain_integration-0.2.0.tar.gz |
|---|---|
| Size | 101.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf68202f8dcb5ee3f86567109503e2035a7adfabe89a45645f4f00ab1638a1f5
|
|
BLAKE2b-256 checksum How to use checksums |
dcfbdea91cb554ce0c9bca7e20ecaa012215f7539806450b9613b42ae3a2f365
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logRelease files / noma_langchain_integration-0.2.0-py3-none-any.whl
| Download URL | noma_langchain_integration-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71c7beb1c43d3fb524d5651492c09f41ec01bb549e0021e4ec4c1d455bce20d8
|
|
BLAKE2b-256 checksum How to use checksums |
11d75084f581a2c2843edafde9dfe60bf97f5633f5e020473139c5eb40643679
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logSecurity for noma-langchain-integration 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for noma_langchain_integration-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.