LangExtract.WireFormat (LangExtract v0.6.0)

Copy Markdown View Source

Port between external LLM format and internal domain.

Serializes %Extraction{} structs to fenced dynamic-key JSON for prompts (matching upstream langextract's default — decided by the 2026-07-05 format A/B, see benchmark/BASELINE.md), and normalizes raw LLM output back to canonical format for the parser. The decode half is format-agnostic: JSON is a YAML subset, so it parses YAML responses and keeps the YAML repair machinery as tolerance for malformed output.

Both directions of the wire format live here on purpose — they share the dynamic-key _attributes contract. Prompt.Builder uses the encode half; Pipeline uses the decode half.

Summary

Functions

format_extractions(extractions)

@spec format_extractions([LangExtract.Extraction.t()]) :: String.t()

normalize(raw)

@spec normalize(String.t()) :: {:ok, map()} | {:error, {:invalid_format, String.t()}}