Expand description
Structured-output enforcer for LLM responses.
Three-pass pipeline: repair → validate → optional retry with
LLM. Repair handles the common cases (markdown fences, trailing
commas, surrounding prose) locally; validation uses a JSON Schema you
supply. If validation fails and you provide a retry function, the
pipeline rerolls with an LLM-friendly hint until success or
max_retries is exhausted.
§Quick start
use agentcast::Caster;
use serde_json::json;
let schema = json!({
"type": "object",
"properties": {
"label": {"type": "string"},
"confidence": {"type": "number"}
},
"required": ["label", "confidence"]
});
let caster = Caster::new(&schema).unwrap();
// The LLM wrapped its JSON in markdown — repair handles that:
let raw = "```json\n{\"label\": \"positive\", \"confidence\": 0.92,}\n```";
let value = caster.parse(raw).unwrap();
assert_eq!(value["label"], "positive");Structs§
- Cast
Issue - One concrete validation issue.
- Caster
- Three-pass caster: repair → validate → optional LLM retry.
Enums§
- Cast
Error - Error returned by
Caster::parseand friends.
Traits§
- RetryFn
- User-supplied retry function: takes the LLM-friendly hint, returns the model’s next attempt as raw text.
Functions§
- repair
- Apply all three repair passes in order.