39 lines
1.6 KiB
Markdown
39 lines
1.6 KiB
Markdown
# 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:
|
||
|
||
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 `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
|
||
```bash
|
||
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:
|
||
```bash
|
||
python main.py
|
||
```
|
||
You will see three pre‑defined inputs (person, meeting, custom) and the parsed JSON output.
|
||
|
||
## How it works
|
||
1. **Schema detection** – a simple regex checks for words like *meeting* or *date* to choose between `PersonInfo` and `MeetingNotes`.
|
||
2. **Prompt** – the same template is used; format instructions are injected from the chosen parser.
|
||
3. **LLM call** – one request to BroJS GPT‑OSS‑20B.
|
||
4. **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.
|