schema-coerce 0.1.0

Coerce LLM JSON values to a simple field-schema: string->int, bool, float; strip wrapper objects; fill defaults. Forgiving structured-output recovery.
Documentation
  • Coverage
  • 100%
    13 out of 13 items documented1 out of 4 items with examples
  • Size
  • Source code size: 23.94 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 400.42 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • MukundaKatta/schema-coerce
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MukundaKatta

schema-coerce

crates.io

Coerce LLM JSON values to a simple field-schema. String→int, "yes"true, unwrap {"result": {...}} wrappers, fill missing fields from defaults.

use schema_coerce::{coerce, Field, Type};
use serde_json::json;

let schema = vec![
    Field { name: "count", ty: Type::Int, default: None },
    Field { name: "ok", ty: Type::Bool, default: Some(json!(false)) },
];
let raw = json!({ "count": "42", "ok": "yes" });
let fixed = coerce(raw, &schema);
assert_eq!(fixed["count"], json!(42));

Pair with llm-json-repair (parse) and json-pluck (extract). MIT or Apache-2.0.