Skip to main content

Crate tool_arg_coerce

Crate tool_arg_coerce 

Source
Expand description

§tool-arg-coerce

Fix common type slips in LLM-generated tool arguments.

LLMs often emit "42" instead of 42 for an integer argument, ["x"] instead of "x" when the schema wants a scalar, or "true" for a bool. This crate gives you a coerce_one function that fixes the obvious cases for a single value, and coerce_args that walks an object against a typed schema.

§Example

use tool_arg_coerce::{coerce_one, Type};
use serde_json::json;

assert_eq!(coerce_one(json!("42"), Type::Int), Some(json!(42)));
assert_eq!(coerce_one(json!("true"), Type::Bool), Some(json!(true)));
assert_eq!(coerce_one(json!(["only"]), Type::String), Some(json!("only")));

Enums§

Type
Target type for coercion.

Functions§

coerce_args
Walk a JSON object, coercing fields named in schema.
coerce_one
Coerce one value to ty. Returns None if no obvious fix exists.