2026-06-04 23:19:41 +00:00
2026-06-04 23:19:30 +00:00
2026-06-04 23:19:36 +00:00
2026-06-04 23:19:41 +00:00

Structured Output Extraction with LangChain & Pydantic

This repository demonstrates how to extract structured data from freeform text using LangChain and Pydantic. Two schemas are supported:

  1. PersonInfo name, optional age, profession, skills.
  2. MeetingNotes date, participants, topics, decisions, next steps.

The extraction is performed in a single LLM call with a prompt that includes the JSON schema. The result is parsed into a validated Pydantic model.

Requirements

langchain>=1.0.0
langchain-openai>=0.0.0
pydantic>=2.0.0
python-dotenv

Install with:

pip install -r requirements.txt

Usage

# Person example
python main.py "Анна, 28 лет, Python-разработчик. Навыки: FastAPI, Docker."

# Meeting example
python main.py "Meeting on 2024-10-01. Participants: Alice, Bob. Topics: Budget, Timeline. Decisions: Increase budget. Next steps: Prepare report."

The script will automatically detect the type of text and output the parsed Pydantic model.

Running from the CLI

You can also run the script interactively:

python main.py
Enter text (or press Ctrl-D to exit):
Анна, 28 лет, Python-разработчик. Навыки: FastAPI, Docker.

License

MIT

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