Tooluck logoTooluck
SKILL.md

langchain-middleware

Agent skill fromlangchain-ai/langchain-skills

INVOKE THIS SKILL when you need human-in-the-loop approval, custom middleware, or structured output. Covers HumanInTheLoopMiddleware for human approval of dangerous tool calls, creating custom middleware with hooks, Command resume patterns, and structured output with Pydantic/Zod.

How to install langchain-middleware

install langchain-middleware
# install the langchain-skills pack with the skills CLI
npx skills add langchain-ai/langchain-skills

# or add only this skill to Claude Code: copy the folder

config/skills/langchain-middleware/

# into

~/.claude/skills/langchain-middleware/ (all projects)

.claude/skills/langchain-middleware/ (one project)

config/skills/langchain-middleware/SKILL.md

MITFull file
1<overview>
2Middleware patterns for production LangChain agents:
3
4- **HumanInTheLoopMiddleware** / **humanInTheLoopMiddleware**: Pause before dangerous tool calls for human approval
5- **Custom middleware**: Intercept tool calls for error handling, logging, retry logic
6- **Command resume**: Continue execution after human decisions (approve, edit, reject)
7
8**Requirements:** Checkpointer + thread_id config for all HITL workflows.
9</overview>
10
11---
12
13## Human-in-the-Loop
14
15<ex-basic-hitl-setup>
16<python>
17Set up an agent with HITL middleware that pauses before sending emails for approval.
18
19```python
20from langchain.agents import create_agent
21from langchain.agents.middleware import HumanInTheLoopMiddleware
22from langgraph.checkpoint.memory import MemorySaver
23from langchain.tools import tool
24
25@tool
26def send_email(to: str, subject: str, body: str) -> str:
27 """Send an email."""
28 return f"Email sent to {to}"
29
30agent = create_agent(
31 model="gpt-4.1",
32 tools=[send_email],
33 checkpointer=MemorySaver(), # Required for HITL
34 middleware=[
35 HumanInTheLoopMiddleware(
36 interrupt_on={
37 "send_email": {"allowed_decisions": ["approve", "edit", "reject"]},
38 }
39 )
40 ],
41)
42```
43</python>
44<typescript>
45Set up an agent with HITL that pauses before sending emails for human approval.
46
47```typescript
48import { createAgent, humanInTheLoopMiddleware } from "langchain";
49import { MemorySaver } from "@langchain/langgraph";
50…

Excerpt shown under the repository's MIT license.

More skills in langchain-skills

Newsletter

Join the Community

Subscribe to our newsletter for the latest news and updates