1.6 KiB
1.6 KiB
Structured Output Extraction with Pydantic
What this project does
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 PydanticOutputParser and the schema’s format instructions.
File structure
models.py– Pydantic models with field descriptions.agent.py– Extraction logic: schema detection, prompt construction, LLM invocation.main.py– CLI demonstrating three example inputs.requirements.txt– Runtime dependencies.README.md– Project description (this file).
Installation
pip install -r requirements.txt
Make sure the environment variable JOURNAL_MCP_PAT is set to your BroJS API key.
Usage examples
Run the script and follow the prompts:
python main.py
You will see three pre‑defined inputs (person, meeting, custom) and the parsed JSON output.
How it works
- Schema detection – a simple regex checks for words like meeting or date to choose between
PersonInfoandMeetingNotes. - Prompt – the same template is used; format instructions are injected from the chosen parser.
- LLM call – one request to BroJS GPT‑OSS‑20B.
- Parsing –
PydanticOutputParser.parse()validates and returns a Pydantic instance.
Extending
Add more schemas by creating new Pydantic models in models.py and extending _detect_schema. The rest of the pipeline remains unchanged.