2026-05-28 18:09:52 +00:00
2026-05-28 18:08:43 +00:00
2026-05-28 18:09:52 +00:00
2026-05-28 18:08:33 +00:00
2026-05-28 18:08:55 +00:00
2026-05-28 18:08:25 +00:00

Structured Output Extraction with Pydantic

What this project does

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 PydanticOutputParser and the schemas 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 predefined 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 GPTOSS20B.
  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.

S
Description
No description provided
Readme 34 KiB
Languages
Python 100%