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).
  • schemas maps tool name to a schema dict.
  • Each schema has required and optional optional field maps.
  • Field type names can be str, int, float, bool, list, or dict.
  • 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):

CaseFormatNotes
Unknown toolunknown_tool:{name}Only error returned (early return).
Missing requiredmissing:{field}Required fields in schema map iteration order.
Extra fieldextra:{field}Lexicographically sorted.
Type mismatchtype:{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

  • int values are accepted for float fields.
  • bool is never accepted for int or float (even though bool subclasses int in 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.
  • bool isn't accepted for int or float.
  • Don't execute the tool.

Editor