Coerce LLM arguments to match expected schema types.
LLMs often return values with incorrect types (e.g., numbers as strings). This function recursively coerces values based on the schema:
"42"
42
"true"
true
"null"
null
"{...}"
{...}
"[...]"
[...]
Use this when SDK provides already-parsed objects but values may have wrong types. For raw JSON strings, use parse instead.
Parsed arguments object from LLM
LLM function parameters schema for type coercion
Coerced arguments with corrected types
Coerce LLM arguments to match expected schema types.
LLMs often return values with incorrect types (e.g., numbers as strings). This function recursively coerces values based on the schema:
"42"→42(when schema expects number)"true"→true(when schema expects boolean)"null"→null(when schema expects null)"{...}"→{...}(when schema expects object)"[...]"→[...](when schema expects array)Use this when SDK provides already-parsed objects but values may have wrong types. For raw JSON strings, use parse instead.