LangChain Middleware & HITL

Implement middleware patterns for LangChain agents with human approval and structured output.

1.1k|86|Updated Jan 22, 2026
One-click install
npx skills add https://github.com/langchain-ai/langchain-skills --skill langchain-middleware-hitl
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: LangChain Middleware & HITL
Source: https://github.com/langchain-ai/langchain-skills/tree/main/config/skills/langchain-middleware
Command: npx skills add https://github.com/langchain-ai/langchain-skills --skill langchain-middleware-hitl

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the critical need for robust production-ready LangChain agents by providing mechanisms for human intervention, custom logic interception, and structured output, thereby enhancing safety, control, and reliability.

Core Features & Use Cases

  • Human-in-the-Loop (HITL): Enables pausing agent execution before sensitive tool calls (like sending emails or deleting data) to allow for human approval, editing, or rejection.
  • Custom Middleware: Allows developers to inject custom logic before or after model calls, tool calls, or agent execution for tasks like error handling, logging, or data validation.
  • Command Resume Patterns: Facilitates resuming agent execution after human decisions, including editing tool arguments or providing feedback.
  • Structured Output: Supports generating structured data outputs using Pydantic or Zod schemas.
  • Use Case: An agent needs to send a customer an important update. HITL middleware can pause the agent before the send_email tool is called, allowing a human to review and approve the message content and recipient, preventing accidental miscommunication.

Quick Start

Set up an agent with HITL middleware that pauses before sending emails for human approval.

Frequently Asked Questions about LangChain Middleware & HITL

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add human-in-the-loop approval for dangerous tool calls in LangChain agents?

Human-in-the-loop approval is implemented using HumanInTheLoopMiddleware to pause agent execution before sensitive tool calls. This allows human operators to review, edit, or reject actions like sending emails or deleting data before proceeding.

How do I resume LangChain agent execution after a human modifies a tool call?

You resume LangChain agent execution using command resume patterns after human decisions. This facilitates continuing the workflow by applying edited tool arguments or incorporating human feedback directly into the agent's next step.

Can I intercept and inject custom logic before or after tool calls in production agents?

Yes, you can intercept tool calls using custom middleware to inject logic before or after model calls. This allows developers to handle errors, log operations, or validate data dynamically during agent execution.

Why does my LangChain agent fail when resuming execution or returning structured output?

Agent execution failures often stem from missing checkpointers, incorrect resume syntax, or improper structured response access. This Skill addresses these critical fixes to ensure reliable command resume patterns and structured output generation.

How do I generate structured output from LangChain agents using Pydantic or Zod schemas?

Structured output generation uses Pydantic or Zod schemas to format agent responses. This ensures the agent returns validated, structured data objects instead of unformatted text, enhancing reliability for downstream tasks.

What is the best way to secure production LangChain agents without blocking automation?

Securing production agents involves applying middleware patterns for human oversight. This approach balances automation with safety by intercepting dangerous tool calls for human approval while allowing standard operations to proceed automatically.