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
| Parser | Use Case |
|---|---|
parse_json | Extract typed JSON structs |
parse_json_value | Extract untyped JSON |
parse_string_list | Extract cleaned string lists (tags, items) |
parse_string_list_raw | Extract string lists without cleaning |
parse_xml_tag | Extract content from an XML tag |
parse_xml_tags | Extract content from multiple XML tags |
parse_choice | Extract a choice from valid options |
parse_number | Extract a numeric value |
parse_number_in_range | Extract a bounded numeric value |
parse_text | Clean text extraction |
parse_yaml | Extract typed YAML (feature: yaml) |
§Traced Variants
| Parser | Use Case |
|---|---|
parse_json_with_trace | JSON extraction with diagnostic trace |
parse_json_value_with_trace | Untyped JSON with diagnostic trace |
parse_string_list_with_trace | List extraction with diagnostic trace |
parse_xml_tag_with_trace | Single XML tag extraction with trace |
parse_xml_tags_with_trace | Multi-tag XML extraction with trace |
parse_choice_with_trace | Choice extraction with trace |
parse_number_with_trace | Numeric extraction with trace |
parse_number_in_range_with_trace | Bounded numeric extraction with trace |
parse_text_with_trace | Text cleanup with trace |
§Configuration
| Type | Purpose |
|---|---|
ParseOptions | Safety limits and behavior toggles |
ParseTrace | Diagnostic output from traced parse calls |
§Shared Utilities
| Function | Purpose |
|---|---|
strip_think_tags | Remove <think> blocks from text |
try_repair_json | Fix 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 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;
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.