Skip to main content

Crate llm_output_parser

Crate llm_output_parser 

Source
Expand description

§LLM Output Parser

Production-grade parser for extracting structured data from LLM responses. Handles think blocks, markdown fences, malformed JSON, and other real-world model output patterns without requiring an additional LLM call.

§Parsers Available

ParserUse Case
parse_jsonExtract typed JSON structs
parse_json_valueExtract untyped JSON
parse_string_listExtract cleaned string lists (tags, items)
parse_string_list_rawExtract string lists without cleaning
parse_xml_tagExtract content from an XML tag
parse_xml_tagsExtract content from multiple XML tags
parse_choiceExtract a choice from valid options
parse_numberExtract a numeric value
parse_number_in_rangeExtract a bounded numeric value
parse_textClean text extraction
parse_yamlExtract typed YAML (feature: yaml)

§Traced Variants

ParserUse Case
parse_json_with_traceJSON extraction with diagnostic trace
parse_json_value_with_traceUntyped JSON with diagnostic trace
parse_string_list_with_traceList extraction with diagnostic trace
parse_xml_tag_with_traceSingle XML tag extraction with trace
parse_xml_tags_with_traceMulti-tag XML extraction with trace
parse_choice_with_traceChoice extraction with trace
parse_number_with_traceNumeric extraction with trace
parse_number_in_range_with_traceBounded numeric extraction with trace
parse_text_with_traceText cleanup with trace

§Configuration

TypePurpose
ParseOptionsSafety limits and behavior toggles
ParseTraceDiagnostic output from traced parse calls

§Shared Utilities

FunctionPurpose
strip_think_tagsRemove <think> blocks from text
try_repair_jsonFix common LLM JSON errors

Re-exports§

pub use choice::parse_choice;
pub use choice::parse_choice_with_trace;
pub use error::ParseError;
pub use error::ParseOptions;
pub use error::ParseTrace;
pub use extract::preprocess;
pub use extract::strip_think_tags;
pub use json::parse_json;
pub use json::parse_json_value;
pub use json::parse_json_value_with_trace;
pub use json::parse_json_with_trace;
pub use list::parse_string_list;
pub use list::parse_string_list_raw;
pub use list::parse_string_list_with_trace;
pub use number::parse_number;
pub use number::parse_number_in_range;
pub use number::parse_number_in_range_with_trace;
pub use number::parse_number_with_trace;
pub use repair::try_repair_json;
pub use text::parse_text;
pub use text::parse_text_with_trace;
pub use xml::parse_xml_tag;
pub use xml::parse_xml_tag_with_trace;
pub use xml::parse_xml_tags;
pub use xml::parse_xml_tags_with_trace;

Modules§

choice
Choice extraction from LLM responses.
error
Error types and configuration for LLM output parsers.
extract
Shared extraction strategies for LLM output parsing.
json
Typed JSON extraction from LLM responses.
list
String list extraction from LLM responses (generalized parse_tags).
number
Numeric value extraction from LLM responses.
repair
Deterministic JSON repair for common LLM output errors.
text
Clean text extraction from LLM responses.
xml
XML-style tag extraction from LLM responses.