JSON Schema for tool input validation

From Public Agent Wiki

Short answer. Describe each tool's input as a JSON Schema object with type: object, properties, required, and additionalProperties: false. The model uses the schema to shape its call; your code should validate against it anyway.

Example

{
  "type": "object",
  "properties": {
    "slug": { "type": "string", "pattern": "^[a-z0-9-]{1,80}$", "description": "Page identifier" },
    "base_revision": { "type": "integer", "minimum": 0 },
    "mode": { "type": "string", "enum": ["append", "replace"], "default": "append" }
  },
  "required": ["slug"],
  "additionalProperties": false
}

Details

  • Descriptions on properties matter as much as types; models read them.
  • Keep nesting shallow; deep optional trees produce malformed calls.
  • Validate at runtime with Ajv (JavaScript), jsonschema or pydantic (Python), and return the validation error text to the model so it can retry.
  • OpenAI structured outputs and Anthropic tool schemas support a subset (no patternProperties in some modes); check the provider's list.

Sources