0
0
LangChainframework~30 mins

Human-in-the-loop with LangGraph in LangChain - Mini Project: Build & Apply

Choose your learning style9 modes available
Human-in-the-loop with LangGraph
📖 Scenario: You are building a simple LangGraph workflow that processes user input and allows a human to review and approve the output before finalizing it. This simulates a real-world scenario where AI suggestions need human validation.
🎯 Goal: Create a LangGraph workflow with a human-in-the-loop step that takes a user question, generates an AI response, and then waits for human approval before completing.
📋 What You'll Learn
Create a LangGraph dictionary called graph with a nodes key containing a node named input_node that accepts a question string.
Add a configuration variable called approval_required set to true to control human approval.
Add a node named ai_response_node that uses LangChain's LLMChain to generate a response from the question.
Add a human_approval_node that simulates human approval by checking approval_required and waits for approval before continuing.
💡 Why This Matters
🌍 Real World
Human-in-the-loop workflows are common in AI applications where human review improves accuracy and trust, such as customer support or content moderation.
💼 Career
Understanding how to build and configure LangGraph workflows with human steps is valuable for AI developers and data scientists working on interactive AI systems.
Progress0 / 4 steps
1
Create the initial LangGraph data structure
Create a dictionary called graph with a key nodes containing a dictionary with one node named input_node. This node should have a type of input and accept a question string.
LangChain
Need a hint?

Think of graph as a map of steps. The input_node is where the user question enters the workflow.

2
Add a configuration variable for approval control
Add a variable called approval_required and set it to true to indicate that human approval is needed.
LangChain
Need a hint?

This variable will help us decide if the workflow should wait for human approval.

3
Add AI response node using LLMChain
Add a node named ai_response_node inside graph['nodes'] with type set to LLMChain. It should take question as input and produce response as output.
LangChain
Need a hint?

This node uses AI to generate an answer from the question.

4
Add human approval node to control workflow
Add a node named human_approval_node inside graph['nodes'] with type set to human. It should take response as input and have a condition that checks if approval_required is true.
LangChain
Need a hint?

This node simulates waiting for a human to approve the AI response before continuing.