1.3 KiB
1.3 KiB
Structured Output Extraction with LangChain & Pydantic
This repository demonstrates how to extract structured data from free‑form text using LangChain and Pydantic. Two schemas are supported:
- PersonInfo – name, optional age, profession, skills.
- 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