MediumAgentsPython 3
Tool Call Schema Validator
Validate tool call names and arguments before runtime execution.
35m3 sample tests7 hidden tests
Validate model-proposed tool calls against a small runtime schema.
Requirements
- Define
validate_call(call, schemas). schemasmaps tool name to a schema dict.- Each schema has
requiredand optionaloptionalfield maps. - Field type names can be
str,int,float,bool,list, ordict. - Return a list of error strings.
- Return
[]when the call is valid. - Reject unknown tools.
- Reject missing required fields.
- Reject extra fields not in required or optional maps.
- Reject wrong field types.
Error string formats
Use these exact codes (tests match the strings):
| Case | Format | Notes |
|---|---|---|
| Unknown tool | unknown_tool:{name} | Only error returned (early return). |
| Missing required | missing:{field} | Required fields in schema map iteration order. |
| Extra field | extra:{field} | Lexicographically sorted. |
| Type mismatch | type:{field}:{expected_type} | Fields in required-then-optional schema order. |
Collect all applicable errors in category order: unknown (early return) → missing → extra → type.
Type acceptance
intvalues are accepted forfloatfields.boolis never accepted forintorfloat(even thoughboolsubclassesintin Python).
Example
python
1schemas = {"search": {"required": {"query": "str"}}}
2assert validate_call({"name": "search", "args": {"query": "cats"}}, schemas) == []
3
4schemas = {"fetch": {"required": {"url": "str", "timeout": "float"}}}
5assert validate_call({"name": "fetch", "args": {"url": "https://x"}}, schemas) == ["missing:timeout"]
6assert validate_call({"name": "delete_all", "args": {}}, {}) == ["unknown_tool:delete_all"]Constraints
- Keep error order deterministic.
boolisn't accepted forintorfloat.- Don't execute the tool.
Editor