langchain-middleware

langchain-middleware is a skill for Claude Code, Codex from langchain-ai/skills-benchmarks. It costs 61 tokens per session (2,583 once invoked), scanned A, a copy of langchain-middleware, MIT.

A LangChain add-on for pausing an AI agent before risky tool calls, adding custom steps around those calls, and returning structured results.

In plain words
What is it for?
Use it to require approval before actions such as sending email, continue after an approve/edit/reject decision, or format results with Pydantic or Zod schemas.
Why use it?
It prevents sensitive actions from happening without human approval and provides one place for logging, retries, and error handling.

Skill for Claude CodeCodex ✓ vendor

Written for no agent in particular: nothing here depends on one.

Good fit Use it to require approval before actions such as sending email, continue after an approve/edit/reject decision, or format results with Pydantic or Zod schemas.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/langchain-ai/skills-benchmarks/langchain-middleware
About the project

skills-benchmarks is a test suite that measures how the design of skill documentation affects Claude Code's adherence to recommended coding patterns. It is used to compare documentation approaches across LangChain-related tasks and other agent workflows. Its catalogue entries represent skills, hooks, instructions, and a plugin used in the benchmark project.

langchain-ai/skills-benchmarks · 120 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add langchain-ai/skills-benchmarks --skill langchain-middleware
Clone the repo
git clone --depth 1 https://github.com/langchain-ai/skills-benchmarks

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for langchain-middleware

README.md
[![agentmods](https://agentmods.dev/badge/skills/langchain-ai/skills-benchmarks/langchain-middleware/github.svg)](https://agentmods.dev/skills/langchain-ai/skills-benchmarks/langchain-middleware)
Your own site
<a href="https://agentmods.dev/skills/langchain-ai/skills-benchmarks/langchain-middleware"><img src="https://agentmods.dev/badge/skills/langchain-ai/skills-benchmarks/langchain-middleware/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for langchain-middleware

Your own site · 80×15
<a href="https://agentmods.dev/skills/langchain-ai/skills-benchmarks/langchain-middleware"><img src="https://agentmods.dev/badge/skills/langchain-ai/skills-benchmarks/langchain-middleware.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 61 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,583 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin 100% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00061 $0.02583
Opus 5.5 $0.00024 $0.01033
Sonnet 5.5 $0.00012 $0.00517
Haiku 4.5 $0.00006 $0.00258

Measured 3mo ago against content hash 4685303d3022, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

langchain-middleware scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

100% identical to langchain-middleware — 392 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

skills/main/langchain-middleware/SKILL.md · 389 lines

How it starts

The opening of the file, as written. The whole thing — 389 lines — stays where its author put it; the contents beside it link to each section on GitHub.

  • HumanInTheLoopMiddleware / humanInTheLoopMiddleware: Pause before dangerous tool calls for human approval
  • Custom middleware: Intercept tool calls for error handling, logging, retry logic
  • Command resume: Continue execution after human decisions (approve, edit, reject)

Requirements: Checkpointer + thread_id config for all HITL workflows.


Human-in-the-Loop

@tool def send_email(to: str, subject: str, body: str) -> str: """Send an email.""" return f"Email sent to {to}"

agent = create_agent( model="gpt-4.1", tools=[send_email], checkpointer=MemorySaver(), # Required for HITL middleware=[ HumanInTheLoopMiddleware( interrupt_on={ "send_email": {"allowed_decisions": ["approve", "edit", "reject"]}, } ) ], )

</python>
<typescript>
Set up an agent with HITL that pauses before sending emails for human approval.
```typescript
import { createAgent, humanInTheLoopMiddleware } from "langchain";
import { MemorySaver } from "@langchain/langgraph";
import { tool } from "@langchain/core/tools";
import { z } from "zod";

const sendEmail = tool(
  async ({ to, subject, body }) => `Email sent to ${to}`,
  {
    name: "send_email",
    description: "Send an email",
    schema: z.object({ to: z.string(), subject: z.string(), body: z.string() }),
  }
);

const agent = createAgent({
  model: "anthropic:claude-sonnet-4-5",
  tools: [sendEmail],
  checkpointer: new MemorySaver(),
  middleware: [
    humanInTheLoopMiddleware({
      interruptOn: { send_email: { allowedDecisions: ["approve", "edit", "reject"] } },
    }),
  ],
});

config = {"configurable": {"thread_id": "session-1"}}

Step 1: Agent runs until it needs to call tool

result1 = agent.invoke({ "messages": [{"role": "user", "content": "Send email to [email protected]"}] }, config=config)

Check for interrupt

if "interrupt" in result1: print(f"Waiting for approval: {result1['interrupt']}")

Step 2: Human approves

result2 = agent.invoke( Command(resume={"decisions": [{"type": "approve"}]}), config=config )

</python>
<typescript>
Run the agent, detect an interrupt, then resume execution after human approval.
```typescript
import { Command } from "@langchain/langgraph";

const config = { configurable: { thread_id: "session-1" } };

// Step 1: Agent runs until it needs to call tool
const result1 = await agent.invoke({
  messages: [{ role: "user", content: "Send email to [email protected]" }]
}, config);

// Check for interrupt
if (result1.__interrupt__) {
  console.log(`Waiting for approval: ${result1.__interrupt__}`);
}

// Step 2: Human approves
const result2 = await agent.invoke(
  new Command({ resume: { decisions: [{ type: "approve" }] } }),
  config
);

Read the full file on GitHub · 389 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 389 lines · 61 tokens per session scan A 4685303d3022

Subscribe to this mod's changes

langchain-middleware is a skill published in the GitHub repository langchain-ai/skills-benchmarks (120 stars, last pushed 2mo ago), licensed MIT. It adds 61 tokens to every session and 2,583 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. It is 100% identical to langchain-middleware, differing in 392 lines, and is treated as a copy.

Related

langchain-middleware compared with skills from other repositories

langchain-middleware next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
langchain-middlewarelangchain-ai/skills-benchmarksSkill1202mo agoMITA61Claude Code, Codex
imagegenopenai/codexSkill137ktodayApache-2.0A113Codex
playwright-climicrosoft/playwrightSkill101ktodayApache-2.0A19Claude Code
browser-automationopenclaw/openclawSkill395ktodayMITA36Claude Code
systematic-debuggingobra/superpowersSkill330k2d agoMITA21Claude Code
free-llm-apismnfst/awesome-free-llm-apisSkill14kyesterdayCC0-1.0A113Claude Code, Codex
next-cache-components-adoptionvercel/next.jsSkill144ktodayMITA95Claude Code