agentcast
Structured-output enforcer for LLM responses. Three-pass: repair → validate → retry-with-LLM (optional). BYO-LLM, BYO-schema.
[]
= "0.1"
Why
Models advertise JSON, then wrap it in markdown fences, leak prose around it, drop a trailing comma, or miss a required field. Without a buffer, you crash. agentcast gives you the buffer:
- Repair — strip ```json fences, extract the largest balanced object from surrounding prose, remove trailing commas.
- Validate — JSON Schema you supply (the same one you sent the model in your tool def).
- Retry — if validation still fails, hand the model a short hint and reroll. Loop up to
max_retries.
Quick start
use Caster;
use json;
let schema = json!;
let caster = new.unwrap;
let raw = "```json\n{\"label\": \"positive\", \"confidence\": 0.92,}\n```";
let value = caster.parse.unwrap; // repair handles the fence + trailing comma
assert_eq!;
With LLM retry
# use Caster;
# use json;
# block_on;
What's in the hint sent back to the model
Output rejected. Fix and try again:
- /confidence: required property missing
- /label: must be one of: ["positive", "negative"]
Short, action-oriented, and what you sent in the tool def is the spec — nothing fancy.
What it doesn't do
- Doesn't call any LLM — you supply the retry function.
- Doesn't write the schema for you — bring the same one you used in your
toolspayload. - Doesn't infer types into a
T: DeserializeOwned; returnsserde_json::Value. Addserde_json::from_value(value)when you have a typed shape.
Sibling: JS @mukundakatta/agentcast
JS users: see @mukundakatta/agentcast on npm.
License
MIT