Files
task-6a1d75e5fd30e81cf3126b1a/README.md
T
2026-06-04 16:07:36 +00:00

797 B

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 (HttpOkEvent and HttpErrorEvent).
  • 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.