0eb83feea775c0a9018e85586c88490b68fc8a59
Structured Output with Discriminated Union
This repository demonstrates how to parse raw API logs into typed events using Pydantic v2 and LangChain ≥1.0. The solution showcases:
- A discriminated union of two event types (
HttpOkEventandHttpErrorEvent). - Structured output from an LLM via
ChatOpenAI.with_structured_output. - Batch parsing of multiple log lines.
- A simple CLI that prints the parsed events and a summary table.
Installation
pip install -r requirements.txt
Usage
# Run with the default example log
python -m src.main
# Or provide your own raw log string
python -m src.main --log "GET /api/test 200 30ms\nPOST /api/submit 500 Internal Server Error"
The script prints each parsed event as a dictionary and a tabular summary.
Description
Languages
Python
100%