> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-docsde-1785859450-e55f5fa.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Middleware integrations

> Integrate with middleware using LangChain Python.

Browse available middleware for different providers or contribute your own to the ecosystem. Learn more about how middleware works in the [middleware overview](/oss/python/langchain/middleware/overview) and how to use middleware with Deep Agents in the [Deep Agents docs](/oss/python/deepagents/customization#middleware).

## Share your middleware

Middleware enables context engineering, harness customization, and runtime safety controls. It is a useful extension point in LangChain and we love highlighting what the community builds with it:

<CardGroup cols={2}>
  <Card title="Add an official integration" icon="package" href="/oss/python/contributing/implement-langchain#middleware">
    Follow the contributing guide to build and publish a middleware package.
  </Card>

  <Card title="Share a community middleware" icon="users" href="https://github.com/langchain-ai/docs">
    Open a PR to the docs repo to add your middleware to the all integrations table.
  </Card>
</CardGroup>

## Featured integrations

<div class="integration-downloads-table">
  | Provider                                                                       | Middleware available                                                                   | Source                                                                                                                                                                                      | Downloads                                                                                                                                                                                                                                               |
  | :----------------------------------------------------------------------------- | :------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
  | [`OpenAI middleware`](/oss/python/integrations/middleware/openai)              | Content moderation                                                                     | [`langchain-ai/langchain`](https://github.com/langchain-ai/langchain/tree/master/libs/partners/openai)                                                                                      | <span data-sort-value="62000000"><a href="https://pypi.org/project/langchain-openai/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-openai/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>       |
  | [`Anthropic middleware`](/oss/python/integrations/middleware/anthropic)        | Prompt caching, bash tool, text editor, memory, and file search                        | [`langchain-ai/langchain`](https://github.com/langchain-ai/langchain/tree/master/libs/partners/anthropic)                                                                                   | <span data-sort-value="21000000"><a href="https://pypi.org/project/langchain-anthropic/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-anthropic/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span> |
  | [`AWS middleware`](/oss/python/integrations/middleware/aws)                    | Prompt caching and AgentCore Payments                                                  | [`langchain-ai/langchain-aws`](https://github.com/langchain-ai/langchain-aws/tree/main/libs/aws), [`aws/bedrock-agentcore-sdk-python`](https://github.com/aws/bedrock-agentcore-sdk-python) | <span data-sort-value="12000000"><a href="https://pypi.org/project/langchain-aws/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-aws/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>             |
  | [`Microsoft Foundry middleware`](/oss/python/integrations/middleware/azure_ai) | Text moderation, image moderation, prompt shield, protected material, and groundedness | [`langchain-ai/langchain-azure`](https://github.com/langchain-ai/langchain-azure/tree/main/libs/azure-ai)                                                                                   | <span data-sort-value="872000"><a href="https://pypi.org/project/langchain-azure-ai/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-azure-ai/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>     |
</div>

## All middleware

<div class="integration-downloads-table">
  | Provider                                                                                                    | Middleware available                                                                                                                                                                                                                                                                                                                                                                     | Source                                                                                                                                                                                      | Downloads                                                                                                                                                                                                                                                            |
  | :---------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | [`OpenAI middleware`](/oss/python/integrations/middleware/openai)                                           | Content moderation                                                                                                                                                                                                                                                                                                                                                                       | [`langchain-ai/langchain`](https://github.com/langchain-ai/langchain/tree/master/libs/partners/openai)                                                                                      | <span data-sort-value="60000000"><a href="https://pypi.org/project/langchain-openai/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-openai/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                    |
  | [`Anthropic middleware`](/oss/python/integrations/middleware/anthropic)                                     | Prompt caching, bash tool, text editor, memory, and file search                                                                                                                                                                                                                                                                                                                          | [`langchain-ai/langchain`](https://github.com/langchain-ai/langchain/tree/master/libs/partners/anthropic)                                                                                   | <span data-sort-value="21000000"><a href="https://pypi.org/project/langchain-anthropic/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-anthropic/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>              |
  | [`AWS middleware`](/oss/python/integrations/middleware/aws)                                                 | Prompt caching and AgentCore Payments                                                                                                                                                                                                                                                                                                                                                    | [`langchain-ai/langchain-aws`](https://github.com/langchain-ai/langchain-aws/tree/main/libs/aws), [`aws/bedrock-agentcore-sdk-python`](https://github.com/aws/bedrock-agentcore-sdk-python) | <span data-sort-value="12000000"><a href="https://pypi.org/project/langchain-aws/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-aws/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                          |
  | [`Microsoft Foundry middleware`](/oss/python/integrations/middleware/azure_ai)                              | Text moderation, image moderation, prompt shield, protected material, and groundedness                                                                                                                                                                                                                                                                                                   | [`langchain-ai/langchain-azure`](https://github.com/langchain-ai/langchain-azure/tree/main/libs/azure-ai)                                                                                   | <span data-sort-value="845000"><a href="https://pypi.org/project/langchain-azure-ai/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-azure-ai/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                  |
  | [`CopilotKit`](/oss/python/langchain/frontend/integrations/copilotkit)                                      | CopilotKit middleware and FastAPI bridge for Deep Agents, create\_agent graphs, AG-UI, and the React and runtime clients                                                                                                                                                                                                                                                                 | [`CopilotKit/CopilotKit`](https://github.com/CopilotKit/CopilotKit)                                                                                                                         | <span data-sort-value="470000"><a href="https://pypi.org/project/copilotkit/" target="_blank">  <img src="https://static.pepy.tech/badge/copilotkit/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                                  |
  | [`compact-middleware`](https://github.com/emanueleielo/compact-middleware)                                  | Claude Code's compaction engine as LangChain middleware. Multi-level context compaction for long-running agents.                                                                                                                                                                                                                                                                         | [`emanueleielo/compact-middleware`](https://github.com/emanueleielo/compact-middleware)                                                                                                     | <span data-sort-value="2000"><a href="https://pypi.org/project/compact-middleware/" target="_blank">  <img src="https://static.pepy.tech/badge/compact-middleware/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                    |
  | [`prompt-shield`](https://github.com/mthamil107/prompt-shield)                                              | Runtime prompt-injection firewall. Scans inputs, tool results, and outputs across detectors and output scanners with block, flag, and log modes.                                                                                                                                                                                                                                         | [`mthamil107/prompt-shield`](https://github.com/mthamil107/prompt-shield)                                                                                                                   | <span data-sort-value="2000"><a href="https://pypi.org/project/prompt-shield-ai/" target="_blank">  <img src="https://static.pepy.tech/badge/prompt-shield-ai/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                        |
  | [`Highflame`](https://github.com/highflame-ai/highflame-sdk)                                                | Runtime AI security guardrails — prompt injection, PII/DLP, content safety — applied as middleware via Highflame Shield (OWASP LLM Top 10).                                                                                                                                                                                                                                              | [`highflame-ai/highflame-sdk`](https://github.com/highflame-ai/highflame-sdk)                                                                                                               | <span data-sort-value="2000"><a href="https://pypi.org/project/highflame/" target="_blank">  <img src="https://static.pepy.tech/badge/highflame/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                                      |
  | [`Cisco AI Defense`](https://github.com/cisco-ai-defense/ai-defense-langchain-middleware)                   | Runtime security inspection                                                                                                                                                                                                                                                                                                                                                              | [`cisco-ai-defense/ai-defense-langchain-middleware`](https://github.com/cisco-ai-defense/ai-defense-langchain-middleware)                                                                   | <span data-sort-value="928"><a href="https://pypi.org/project/langchain-cisco-aidefense/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-cisco-aidefense/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>       |
  | [`langchain-collapse`](https://github.com/johanity/langchain-collapse)                                      | Preventive context management. Collapses consecutive tool-call groups before they fill the context window.                                                                                                                                                                                                                                                                               | [`johanity/langchain-collapse`](https://github.com/johanity/langchain-collapse)                                                                                                             | <span data-sort-value="877"><a href="https://pypi.org/project/langchain-collapse/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-collapse/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                     |
  | [`OpenBox`](https://docs.openbox.ai/getting-started/langgraph)                                              | Real-time governance for LangGraph and Deep Agents. Policies, guardrails, HITL, OTel hook governance, and behavior rules.                                                                                                                                                                                                                                                                | [`OpenBox-AI/openbox-langgraph-sdk-python`](https://github.com/OpenBox-AI/openbox-langgraph-sdk-python)                                                                                     | <span data-sort-value="843"><a href="https://pypi.org/project/openbox-langgraph-sdk-python/" target="_blank">  <img src="https://static.pepy.tech/badge/openbox-langgraph-sdk-python/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span> |
  | [`langchain-task-steering`](https://github.com/edvinhallvaxhiu/langchain-task-steering)                     | Implicit state-machine middleware for ordered task pipelines with per-task tool scoping, dynamic prompt injection, and composable completion validation.                                                                                                                                                                                                                                 | [`edvinhallvaxhiu/langchain-task-steering`](https://github.com/edvinhallvaxhiu/langchain-task-steering)                                                                                     | <span data-sort-value="865"><a href="https://pypi.org/project/langchain-task-steering/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-task-steering/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>           |
  | [`advisor-middleware`](https://github.com/emanueleielo/advisor-middleware)                                  | Claude Code's advisor pattern as LangChain middleware. Pairs a fast executor model with a powerful advisor model that intervenes only on critical decisions.                                                                                                                                                                                                                             | [`emanueleielo/advisor-middleware`](https://github.com/emanueleielo/advisor-middleware)                                                                                                     | <span data-sort-value="770"><a href="https://pypi.org/project/advisor-middleware/" target="_blank">  <img src="https://static.pepy.tech/badge/advisor-middleware/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                     |
  | [`RelayShield`](https://relayshield.net)                                                                    | Mandatory pre-execution gate that blocks connect\_mcp\_server and install\_mcp\_package tool calls when RelayShield reports risk.                                                                                                                                                                                                                                                        | [`nzdsf2-gif/langchain-relayshield`](https://github.com/nzdsf2-gif/langchain-relayshield)                                                                                                   | <span data-sort-value="651"><a href="https://pypi.org/project/langchain-relayshield/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-relayshield/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>               |
  | [`langchain-router`](https://github.com/johanity/langchain-router)                                          | Phase-based model routing. Routes execution turns to a fast model, keeps the primary for planning and recovery.                                                                                                                                                                                                                                                                          | [`johanity/langchain-router`](https://github.com/johanity/langchain-router)                                                                                                                 | <span data-sort-value="597"><a href="https://pypi.org/project/langchain-router/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-router/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                         |
  | [`comply54`](https://comply54.io/langchain)                                                                 | Runtime compliance enforcement for AI agents under African data protection and financial-sector regulations (deny, escalate, audit, or allow).                                                                                                                                                                                                                                           | [`comply54/langchain-comply54`](https://github.com/comply54/langchain-comply54)                                                                                                             | <span data-sort-value="560"><a href="https://pypi.org/project/langchain-comply54/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-comply54/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                     |
  | [`text2sql-framework`](https://github.com/Text2SqlAgent/text2sql-framework)                                 | Replaces RAG with recursive tool use — the agent explores, writes, tests, and self-corrects using one execute\_sql tool.                                                                                                                                                                                                                                                                 | [`Text2SqlAgent/text2sql-framework`](https://github.com/Text2SqlAgent/text2sql-framework)                                                                                                   | <span data-sort-value="563"><a href="https://pypi.org/project/text2sql-framework/" target="_blank">  <img src="https://static.pepy.tech/badge/text2sql-framework/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                     |
  | [`langchain-distil`](https://github.com/dshakes/distil)                                                     | Reversible, certified context compression. Digests large tool outputs and message history before the model call (tool and function messages reversibly, human and system losslessly, the model messages never rewritten), with byte-exact recovery of every digest. Decision-equivalence between compressed and full context is certified offline by a statistical non-inferiority gate. | [`dshakes/distil`](https://github.com/dshakes/distil)                                                                                                                                       | <span data-sort-value="374"><a href="https://pypi.org/project/langchain-distil/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-distil/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                         |
  | [`Tessera`](https://github.com/kenithphilip/Tessera)                                                        | Signed trust labels and taint-tracking that gate tool calls when context contains untrusted segments.                                                                                                                                                                                                                                                                                    | [`kenithphilip/Tessera`](https://github.com/kenithphilip/Tessera)                                                                                                                           | <span data-sort-value="357"><a href="https://pypi.org/project/tessera-mesh/" target="_blank">  <img src="https://static.pepy.tech/badge/tessera-mesh/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                                 |
  | [`NoPII`](https://github.com/Enigma-Vault/NoPII/tree/main/integrations/langchain-nopii-middleware)          | Runtime PII tokenization. Detects personal data in outbound prompts, replaces it with deterministic vault tokens before the request reaches the LLM, and restores the original values in the response.                                                                                                                                                                                   | [`Enigma-Vault/NoPII`](https://github.com/Enigma-Vault/NoPII/tree/main/integrations/langchain-nopii-middleware)                                                                             | <span data-sort-value="165"><a href="https://pypi.org/project/langchain-nopii-middleware/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-nopii-middleware/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>     |
  | [`AxioRank`](https://app.axiorank.com/docs/integrations/langchain)                                          | Security gateway for AI agents: score tool calls and model turns against policy with allow, deny, and redact.                                                                                                                                                                                                                                                                            | [`AxioRank/langchain-axiorank`](https://github.com/AxioRank/langchain-axiorank)                                                                                                             | <span data-sort-value="155"><a href="https://pypi.org/project/langchain-axiorank/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-axiorank/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                     |
  | [`OWASP Agent Memory Guard`](https://owasp.org/www-project-agent-memory-guard/)                             | Runtime defense against AI agent memory poisoning (OWASP ASI06). Scans messages, model responses, and tool outputs locally with block, warn, and strip modes.                                                                                                                                                                                                                            | [`OWASP/www-project-agent-memory-guard`](https://github.com/OWASP/www-project-agent-memory-guard/tree/main/integrations/langchain-agent-memory-guard)                                       | <span data-sort-value="127"><a href="https://pypi.org/project/langchain-agent-memory-guard/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-agent-memory-guard/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span> |
  | [`DNS-AID`](https://github.com/IngmarVG-IB/langchain-dns-aid)                                               | DNS-based agent discovery via the DNS-AID protocol. Auto-publishes agents on startup, auto-unpublishes on shutdown, and provides discovery tools.                                                                                                                                                                                                                                        | [`IngmarVG-IB/langchain-dns-aid`](https://github.com/IngmarVG-IB/langchain-dns-aid)                                                                                                         | <span data-sort-value="115"><a href="https://pypi.org/project/langchain-dns-aid/" target="_blank">  <img src="https://static.pepy.tech/badge/langchain-dns-aid/month" alt="Downloads per month" noZoom class="rounded not-prose" /></a></span>                       |
  | [`ATR Guardrail`](https://github.com/Agent-Threat-Rule/agent-threat-rules/tree/main/integrations/langchain) | Runtime detection of prompt injection, tool poisoning, and unsafe tool calls using Agent Threat Rules. Halts the agent or blocks the tool call on a critical finding and keeps an audit trail.                                                                                                                                                                                           | [`Agent-Threat-Rule/agent-threat-rules`](https://github.com/Agent-Threat-Rule/agent-threat-rules/tree/main/integrations/langchain)                                                          | <span data-sort-value="-1">N/A</span>                                                                                                                                                                                                                                |
  | [`Haldir`](https://haldir.xyz/docs)                                                                         | Governance layer for LangChain agents with scoped sessions, encrypted secrets, hash-chained audit, and policy enforcement.                                                                                                                                                                                                                                                               | [`ExposureGuard/haldir`](https://github.com/ExposureGuard/haldir/tree/main/integrations/langchain-haldir)                                                                                   | <span data-sort-value="-1">N/A</span>                                                                                                                                                                                                                                |
  | [`eager-tools`](https://github.com/cloudthinker-ai/eager-tools)                                             | Reduces agent wall-clock latency by dispatching each tool call the moment its streaming block closes, overlapping tool execution with LLM generation.                                                                                                                                                                                                                                    | [`cloudthinker-ai/eager-tools`](https://github.com/cloudthinker-ai/eager-tools)                                                                                                             | <span data-sort-value="-1">N/A</span>                                                                                                                                                                                                                                |
  | [`langgraph-state-machine`](https://github.com/mahmoud661/langgraph-state-machine)                          | Section-based flow control for LangGraph React agents. Divides conversations into discrete phases with scoped tools, prompts, auto-transitions, branching, and optional per-section LLM override.                                                                                                                                                                                        | [`mahmoud661/langgraph-state-machine`](https://github.com/mahmoud661/langgraph-state-machine)                                                                                               | <span data-sort-value="-1">N/A</span>                                                                                                                                                                                                                                |
</div>

<Info>
  If you'd like to contribute an integration, see [Contributing integrations](/oss/python/contributing#add-a-new-integration).
</Info>

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/middleware/index.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
