Structured Output Extraction with LangChain and Pydantic

This project demonstrates how to extract structured data from raw text using LangChain and Pydantic.
It supports two schemas:

  • PersonInfo name, age, profession, skills
  • MeetingNotes date, participants, topics, decisions, next steps

The CLI automatically selects the appropriate schema based on the input text and prints the parsed object and a short summary.

Prerequisites

  • Python 3.10+
  • An OpenAI API key (or compatible LLM provider)

Installation

# Create a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate   # On Windows use `.venv\Scripts\activate`

# Install dependencies
pip install -r requirements.txt

Configuration

Create a .env file in the project root with your OpenAI key:

OPENAI_API_KEY=sk-...

Usage

Run the CLI:

python src/cli.py run

You will be prompted to provide text or a file path.
If no input is given, example texts for both schemas are displayed.

Example

python src/cli.py run --file example.txt

The output will look like:

Detected schema: person

Parsed object:
{
  "name": "Анна",
  "age": 28,
  "profession": "Python-разработчик",
  "skills": [
    "FastAPI",
    "Docker"
  ]
}

Summary:
Person: Анна, age=28, profession=Python-разработчик, skills=FastAPI, Docker

Project Structure

src/
├── __init__.py
├── cli.py
├── main.py
└── models.py
requirements.txt
README.md

License

MIT License

S
Description
BroJS: Экзамен: Структурированный вывод (Pydantic)
Readme 27 KiB
Languages
Python 100%