Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

LangGraph Workflow Example (Finished Version)

This is the finished version of the Week 3 routing workflow, here as a lifeline if you get stuck. It shows one good way to reach the goal, not the only one, so try it yourself first. The student-facing starter is simple-data-cleaning-langgraph-workflow-start.

A simple example demonstrating how to build workflows with LangGraph for data processing.

How It Works

The workflow follows these steps:

  1. Load Data - Reads the CSV file into a pandas DataFrame
  2. Summarize Data - Generates comprehensive summary including:
    • Statistical description (.describe())
    • Dataset info (.info())
    • Explicit missing value counts
  3. LLM Reasoning - Uses GPT-4o-mini to analyze the summary and decide which action to take
  4. Conditional Routing - Routes to appropriate cleaning node based on LLM decision
  5. Data Cleaning - Can execute:
    • Handle Missing Values - Fills numeric missing values with column means
    • Remove Outliers - Removes outliers using IQR (Interquartile Range) method
    • Clean Both - Fills missing values first, then removes outliers
  6. Describe Data - Generates statistical summary of cleaned data
  7. Output Results - Prints the action taken and final summary

Setup

Windows (PowerShell)

  1. Verify Python is installed (Python 3.9 or higher required):

    python --version

    If not installed, download from python.org

  2. Install Poetry:

    (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

    After installation, restart your terminal or IDE. If poetry command is not found, add %APPDATA%\Python\Scripts to your system PATH.

  3. Install dependencies:

    poetry install
  4. Set up your OpenAI API key:

    copy .env.example .env

    Then edit .env and add your OpenAI API key: OPENAI_API_KEY=sk-your-key-here

macOS/Linux

  1. Install Poetry (if not already installed):

    curl -sSL https://install.python-poetry.org | python3 -
  2. Install dependencies:

    poetry install
  3. Set up your OpenAI API key:

    cp .env.example .env

    Then edit .env and add your OpenAI API key: OPENAI_API_KEY=sk-your-key-here

Running the Example

From the project root:

poetry run python workflows/simple_clean_data_workflow.py

The workflow will:

  1. Save a workflow graph visualization to outputs/workflow_graph.png
  2. Load data from data/missing_and_outliers.csv (you can change this in the script)
  3. Use an LLM to analyze the data and decide which cleaning action to take
  4. Execute the appropriate cleaning steps
  5. Display the results

Project Structure

.
├── README.md
├── pyproject.toml
├── .env.example
├── .gitignore
│
├── data/
│   ├── missing.csv              # Data with only missing values
│   ├── outliers.csv             # Data with only outliers
│   └── missing_and_outliers.csv # Data with both issues
│
├── workflows/
│   └── simple_clean_data_workflow.py   # Main workflow implementation
│
└── outputs/
    └── .gitkeep                 # Generated files (graphs, reports)

Folder Organization:

  • data/ - Sample CSV files with different data quality issues
  • workflows/ - LangGraph workflow scripts
  • outputs/ - Generated outputs (visualizations, reports)

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages