langchain-middleware

Add human approval and custom middleware to LangChain agent tool calls.

Updated Mar 7, 2026
One-click install
npx skills add https://github.com/tivon-x/deep-research --skill langchain-middleware-tivon-x
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: langchain-middleware
Source: https://github.com/tivon-x/deep-research/tree/main/.agents/skills/langchain-middleware
Command: npx skills add https://github.com/tivon-x/deep-research --skill langchain-middleware-tivon-x

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides essential middleware patterns for production LangChain agents, enabling human oversight for critical actions, custom logic interception, and structured output.

Core Features & Use Cases

  • Human-in-the-Loop (HITL): Pause agent execution before dangerous tool calls (like sending emails or deleting data) for explicit human approval, editing, or rejection.
  • Custom Middleware: Implement custom logic to intercept tool calls for error handling, logging, or retries.
  • Structured Output: Ensure agent outputs conform to predefined schemas using Pydantic or Zod.
  • Use Case: An agent needs to send a sensitive customer update email. HITL middleware will pause the agent, allowing a human to review and approve the email content before it's sent.

Quick Start

Configure an agent with HumanInTheLoopMiddleware to pause before calling the 'send_email' tool.

Frequently Asked Questions about langchain-middleware

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

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

Human-in-the-loop approval for LangChain agents pauses execution before dangerous tool calls by using custom middleware interception, allowing a human to review, edit, or reject the action. This requires configuring a checkpointer and thread_id for state management.

Can I intercept LangChain tool calls for custom logging or error handling?

You can intercept LangChain tool calls for custom logging or error handling by implementing custom middleware hooks. This allows you to inject custom logic into the agent execution flow to manage errors or add operational logging.

How do I ensure LangChain agent outputs conform to a predefined schema?

To ensure LangChain agent outputs conform to a predefined schema, you can use the structured output generation feature. This enforces specific data formats using schema validation tools like Pydantic or Zod.

Do I need a checkpointer to use human-in-the-loop middleware with LangChain?

A checkpointer is required for human-in-the-loop operations with LangChain middleware. You must also provide a thread_id to successfully pause execution and resume after human approval or rejection feedback.

What is the best way to pause a LangChain agent before sending an email?

The best way to pause a LangChain agent before sending an email is to apply HumanInTheLoopMiddleware. It pauses execution before sensitive tool calls, allowing a human to review the email content and explicitly approve or reject it.