49 lines
1.3 KiB
Markdown
49 lines
1.3 KiB
Markdown
# 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:
|
||
|
||
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
|
||
|
||
```text
|
||
langchain>=1.0.0
|
||
langchain-openai>=0.0.0
|
||
pydantic>=2.0.0
|
||
python-dotenv
|
||
```
|
||
|
||
Install with:
|
||
|
||
```bash
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
## Usage
|
||
|
||
```bash
|
||
# 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:
|
||
|
||
```bash
|
||
python main.py
|
||
Enter text (or press Ctrl-D to exit):
|
||
Анна, 28 лет, Python-разработчик. Навыки: FastAPI, Docker.
|
||
```
|
||
|
||
## License
|
||
|
||
MIT |