LangExtract.WireFormat (LangExtract v0.11.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/decisions/), and normalizes raw LLM output back to canonical format for the parser. Decoding is JSON-only (since 0.7.0; the YAML tolerance path and its repair machinery were removed once JSON became the wire format).

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

Suffix reserved for attribute-carrier keys ("<class>_attributes").

Class names reserved by the wire contract.

Functions

attribute_suffix()

@spec attribute_suffix() :: String.t()

Suffix reserved for attribute-carrier keys ("<class>_attributes").

A class name ending in it would decode as attributes for another class, so template construction rejects those up front as well.

format_extractions(extractions)

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

normalize(raw)

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

reserved_marker_keys()

@spec reserved_marker_keys() :: [String.t()]

Class names reserved by the wire contract.

Encoding one of these as a dynamic key collides with the canonical "class"/"text" marker keys the decoder passes through untouched, so template construction rejects them up front.