Home Blog Reviews Best Picks Guides Tools Glossary Advertise Subscribe Free
Tech Frontline Jun 24, 2026 5 min read

How to Build an End-to-End Approval Workflow Automation App with LangChain

A step-by-step, developer-friendly tutorial for building an entire approval workflow app using LangChain and AI APIs.

T
Tech Daily Shot Team
Published Jun 24, 2026
How to Build an End-to-End Approval Workflow Automation App with LangChain

Approval workflows are the backbone of countless business processes—expense reports, HR leave requests, procurement, legal reviews, and more. As we covered in our Ultimate Playbook for AI-Powered Approval Workflow Automation, the impact of AI and LLMs on automating these workflows is transformative. In this deep-dive, you'll learn how to build a practical, end-to-end approval workflow automation app using LangChain, the leading open-source framework for LLM-powered applications.

This tutorial guides you through every step: from project setup, prompt engineering, and workflow logic, to integrating user input and generating approval decisions. Whether you're looking to automate expense approvals, HR requests, or procurement flows, you'll find actionable code and patterns you can adapt to your use case.

For a manager’s perspective, see Automating Expense Report Approvals with AI or dive into Automating HR Leave Request Approvals with AI: Best Practices & Pitfalls for HR-specific workflows.


Prerequisites

Tools & Libraries

1. Project Setup

  1. Create a new project directory:
    mkdir langchain-approval-workflow && cd langchain-approval-workflow
  2. Initialize a virtual environment:
    python3 -m venv .venv
    source .venv/bin/activate
  3. Install required packages:
    pip install langchain openai python-dotenv typer
  4. Create a .env file with your OpenAI API key:
    OPENAI_API_KEY=sk-...
        
    Never commit this file to source control.
  5. Directory structure should look like:
    langchain-approval-workflow/
    ├── .env
    ├── main.py
    ├── .venv/
        

2. Define the Approval Workflow Logic

  1. Decide on your approval scenario. For this tutorial, we'll automate an expense report approval process, but you can adapt this to HR, procurement, or contract reviews.
  2. Define the workflow steps:
    • User submits an expense request (amount, description, category)
    • LLM reviews the request based on company policy
    • LLM returns: APPROVED, REJECTED, or ESCALATE with a reason
  3. Create main.py and define the input schema:
    
    import os
    from dotenv import load_dotenv
    
    load_dotenv()
    
    def get_expense_request():
        print("Submit a new expense request.")
        employee = input("Employee Name: ")
        amount = float(input("Amount (USD): "))
        category = input("Category (e.g., Travel, Meals): ")
        description = input("Description: ")
        return {
            "employee": employee,
            "amount": amount,
            "category": category,
            "description": description
        }
        

3. Configure LangChain and LLM Integration

  1. Set up OpenAI and LangChain:
    
    from langchain.chat_models import ChatOpenAI
    from langchain.prompts import ChatPromptTemplate
    from langchain.schema import SystemMessage, HumanMessage
    
    llm = ChatOpenAI(
        openai_api_key=os.getenv("OPENAI_API_KEY"),
        model="gpt-3.5-turbo",  # You can use "gpt-4" if available
        temperature=0.0
    )
        
  2. Design a robust prompt template:
    
    SYSTEM_PROMPT = """
    You are an Expense Approval Bot.
    Company policy:
    - Approve expenses under $500 unless the description is suspicious.
    - Escalate expenses between $500 and $2000 to a manager.
    - Reject expenses over $2000.
    - Always provide a reason for your decision.
    
    Respond in the following JSON format:
    {{
      "decision": "APPROVED" | "REJECTED" | "ESCALATE",
      "reason": ""
    }}
    """
    
    def build_prompt(expense):
        return [
            SystemMessage(content=SYSTEM_PROMPT),
            HumanMessage(content=f"""
    Expense request:
    Employee: {expense['employee']}
    Amount: ${expense['amount']}
    Category: {expense['category']}
    Description: {expense['description']}
    """)
        ]
        

4. Run the Approval Workflow End-to-End

  1. Combine everything in main.py:
    
    def main():
        expense = get_expense_request()
        messages = build_prompt(expense)
        response = llm(messages)
        print("\nLLM Response:\n", response.content)
    
    if __name__ == "__main__":
        main()
        

    Screenshot Description: The terminal displays a prompt for user input (employee name, amount, category, description), then outputs the LLM's JSON decision and reason.

  2. Run your workflow in the terminal:
    python main.py

    Example output:

    Submit a new expense request.
    Employee Name: Alice
    Amount (USD): 250
    Category (e.g., Travel, Meals): Meals
    Description: Team lunch with clients
    
    LLM Response:
    {
      "decision": "APPROVED",
      "reason": "Expense is under $500 and appears business-related."
    }
          

5. Parse and Display the LLM's Decision

  1. Parse the JSON response for automation:
    
    import json
    
    def parse_decision(response_content):
        try:
            decision_json = json.loads(response_content)
            print(f"Decision: {decision_json['decision']}")
            print(f"Reason: {decision_json['reason']}")
            return decision_json
        except json.JSONDecodeError:
            print("Error: Could not parse LLM response. Raw output:")
            print(response_content)
            return None
        
  2. Update main() to use the parser:
    
    def main():
        expense = get_expense_request()
        messages = build_prompt(expense)
        response = llm(messages)
        print("\nLLM Response:\n", response.content)
        parse_decision(response.content)
        

6. (Optional) Add a CLI for Batch Processing

  1. Enable batch approval from a CSV file using typer:
    
    import typer
    import csv
    
    app = typer.Typer()
    
    @app.command()
    def approve_csv(csv_file: str):
        with open(csv_file, newline='') as f:
            reader = csv.DictReader(f)
            for row in reader:
                print(f"\nProcessing: {row}")
                messages = build_prompt(row)
                response = llm(messages)
                print("LLM Response:", response.content)
                parse_decision(response.content)
    
    if __name__ == "__main__":
        app()
        

    Run batch approval:

    python main.py approve-csv expenses.csv

    Screenshot Description: The terminal processes each expense row from the CSV, displaying LLM decisions for each.

7. Next-Level: Customizing Prompts & Multi-Step Workflows

  1. Experiment with prompt engineering: Adapt company policy, add context, or chain multiple LLM calls. For advanced patterns, see Prompt Engineering for Approval Workflows and Deep Dive: Generative AI Prompt Engineering for Approval Workflow Automation.
  2. Build multi-level approvals: For complex organizations, chain LLM outputs to trigger manager or director review. See Automating Multi-Level Approval Workflows: Hands-On Guide for Large Enterprises for practical blueprints.

Common Issues & Troubleshooting

Next Steps


With this hands-on LangChain approval workflow tutorial, you have a tested foundation for building, customizing, and scaling AI-powered approval automations. Adapt the code, refine your prompts, and plug into your business processes—unlocking efficiency and auditability at scale.

LangChain approval workflow AI automation tutorial coding

Related Articles

Tech Frontline
Best APIs for Customizing AI Workflow Automation in 2026: A Developer’s Guide
Jun 24, 2026
Tech Frontline
Unlocking the Power of Workflow Automation APIs in Finance: A 2026 Developer's Guide
Jun 23, 2026
Tech Frontline
How to Build Custom AI Integrations for Workflow Automation—A 2026 Developer's Tutorial
Jun 23, 2026
Tech Frontline
Best Practices for Version Control in AI Workflow Automation Projects
Jun 22, 2026
Free & Interactive

Tools & Software

100+ hand-picked tools personally tested by our team — for developers, designers, and power users.

🛠 Dev Tools 🎨 Design 🔒 Security ☁️ Cloud
Explore Tools →
Step by Step

Guides & Playbooks

Complete, actionable guides for every stage — from setup to mastery. No fluff, just results.

📚 Homelab 🔒 Privacy 🐧 Linux ⚙️ DevOps
Browse Guides →
Advertise with Us

Put your brand in front of 10,000+ tech professionals

Native placements that feel like recommendations. Newsletter, articles, banners, and directory features.

✉️
Newsletter
10K+ reach
📰
Articles
SEO evergreen
🖼️
Banners
Site-wide
🎯
Directory
Priority

Stay ahead of the tech curve

Join 10,000+ professionals who start their morning smarter. No spam, no fluff — just the most important tech developments, explained.