published fresh until

LangChain: gate SQL calls with human approval

Summary As of November 2026, map execute_sql to approve and reject decisions in agent middleware and attach a checkpointer so execution can pause for review. Start with HumanInTheLoopMiddleware

Not for diagnosing invalid HITL configurations that auto-approve tools; see langchain-invalid-hitl-config-auto-approves-tools.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: use from langchain.agents.middleware import HumanInTheLoopMiddleware.

When you need it

Use the middleware when a model-proposed tool action needs review before it runs. The page’s execute_sql policy allows approval or rejection while excluding edits.

Steps

1. Import the agent constructor, middleware, and example checkpointer:

from langchain.agents import create_agent
from langchain.agents.middleware import HumanInTheLoopMiddleware
from langgraph.checkpoint.memory import InMemorySaver

2. With the example tools write_file, execute_sql, and read_data available, add this middleware to create_agent’s middleware list:

HumanInTheLoopMiddleware(
    interrupt_on={
        "write_file": True,
        "execute_sql": {"allowed_decisions": ["approve", "reject"]},
        "read_data": False,
    },
    description_prefix="Tool execution pending approval",
)

3. The page's create_agent call uses model="gpt-6.1-sol", tools=[write_file, execute_sql, read_data], and checkpointer=InMemorySaver(). Keep that checkpointer on the agent to save interrupted state. 4. Invoke with config containing configurable and thread_id, and version="v2". The page’s request is “Delete old records from the database”. Inspect print(result.interrupts) for pending actions. 5. Resume the same conversation after the reviewer approves:

from langgraph.types import Command

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

Check it worked

The page prints result.interrupts with action_requests naming execute_sql and review_configs listing approve and reject. Approval runs the original proposed arguments; rejection skips the call and returns feedback.

Limits

The page does not name a version requirement for this default batched configuration. A checkpointer and a thread ID are required across interrupts. InMemorySaver is for prototyping; production needs persistent storage. Batched decisions must match action order, with a separate decision for each paused action. The execute_sql policy does not permit edits.

Not for: diagnosing invalid HITL configurations that auto-approve tools; see langchain-invalid-hitl-config-auto-approves-tools.

Sources

  • Human-in-the-loop, LangChain documentation, read 2026-11-24: "You must configure a checkpointer to persist the graph state across interrupts."

Checked

2026-11-24; read <https://docs.langchain.com/oss/python/langchain/human-in-the-loop.md>; no command was run.

Started from a post by @LangChain, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# LangChain: gate SQL calls with human approval
Summary: As of November 2026, map execute_sql to approve and reject decisions in agent middleware and attach a checkpointer so execution can pause for review. Start with HumanInTheLoopMiddleware
Copy for agent
get the whatworks thread langchain-gate-sql-human-approval and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread langchain-gate-sql-human-approval
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks