Expand description
Typed extraction of tools/call arguments.
Every tool used to read its optional arguments with a bare
args.get("max_tokens").and_then(Value::as_u64), so the None branch —
“the caller sent something, but not of the declared type” — was
indistinguishable from “the caller sent nothing” and the flag was simply
omitted from the spawned argv. That is a wrong-answer channel: the client
believes it asserted something the server never applied, and the result
JSON echoes the CLI’s default so the drop is undetectable downstream.
apr.qa’s assert_tps is the sharpest case — passed as a JSON string it
disarmed the throughput gate entirely (#2403).
The rules here are deliberately narrow:
- absent or JSON
null→Ok(None)(the argument is optional) - the declared JSON type →
Ok(Some(v)) - a string that parses exactly into the declared type →
Ok(Some(v)). LLM clients routinely emit numbers as JSON strings, so"8"for an integer is the common path, not an exotic one — coercing it is what the caller meant and it is lossless. - anything else →
Err(message), which the tool turns into anisError: trueresult. This matches the one field that already validated before this module existed,apr.serve’sport.
Nothing is ever silently dropped.
Functions§
- json_
type_ name - JSON type name as it appears in a JSON Schema
typekeyword. - opt_
bool - Extract a boolean argument (
"type": "boolean"). - opt_f64
- Extract a floating-point argument (
"type": "number"). - opt_str
- Extract a string argument (
"type": "string"). - opt_u64
- Extract a non-negative integer argument (
"type": "integer"). - require_
str - Extract a required string argument from a
tools/callargumentsobject. - required_
str - Extract a required string argument, reporting absence and wrong type distinctly.
Type Aliases§
- ArgResult
Ok(None)= absent,Ok(Some(v))= present and usable,Err= present but not convertible to the declared type.