← CookbookView source on GitHub ↗

LangChain Data Agent PoC

This is a small natural-language-to-SQL data agent inspired by the architecture of eosho/langchain_data_agent, but implemented from scratch for this cookbook.

The goal is a compact PoC, not a full data platform. It keeps the useful shape:

  1. Rewrite follow-up questions into standalone questions.
  2. Route the question to a specialized data domain.
  3. Generate SQL for the selected schema.
  4. Validate that the SQL is read-only and scoped to allowed tables.
  5. Execute against a local sample dataset.
  6. Summarize the result and suggest a simple chart.

It uses Nebius Token Factory through LangChain's OpenAI-compatible client, plus LangGraph for the pipeline and Streamlit for the UI.

What is included

Setup

cd agents/langchain_data_agent_poc
python -m venv .venv && source .venv/bin/activate
pip install -e .
cp env.example .env

Edit .env and add your Nebius key:

NEBIUS_API_KEY=your-nebius-token-factory-key
NEBIUS_MODEL=Qwen/Qwen3-30B-A3B

Run the Streamlit UI

streamlit run app.py

Run the CLI

python main.py

Sample questions

Sales:

Support:

Project structure

langchain_data_agent_poc/
├── agent.py          # LangGraph pipeline and Nebius LLM calls
├── app.py            # Streamlit UI
├── config.py         # Domain definitions and sample prompts
├── dataset.py        # CSV to in-memory SQLite loader
├── main.py           # CLI entrypoint
├── sql_safety.py     # Read-only SQL validation
├── visualization.py  # Simple chart suggestion logic
├── data/
│   ├── customers.csv
│   ├── orders.csv
│   ├── products.csv
│   └── support_tickets.csv
├── env.example
└── pyproject.toml

Notes

This example deliberately avoids external database ingestion, cloud warehouse connectors, auth adapters, A2A protocol, and production config loaders. Those are valuable in a full platform, but they obscure the core data-agent loop for a cookbook PoC.