Skip to content

fix(tools): preserve $defs in generated tool schemas - #81

Closed
HamzaKhanBUIC wants to merge 1 commit into
getdownandcode:mainfrom
HamzaKhanBUIC:fix/tool-schema-defs
Closed

HamzaKhanBUIC wants to merge 1 commit into
getdownandcode:mainfrom
HamzaKhanBUIC:fix/tool-schema-defs

Conversation

@HamzaKhanBUIC

Copy link
Copy Markdown

Summary

Fixes #70.

Preserves $defs and �dditionalProperties in create_tool_schema, preventing unresolvable $ref dangling pointers when tools use Enum or nested BaseModel parameters.

Problem

When constructing tool parameters, create_tool_schema extracted only properties and
equired from Pydantic's model_json_schema(). Nested models and enums are emitted by Pydantic as $ref: #//..., but the $defs block was dropped. This left emitted schemas with unresolvable references, causing LLM providers (e.g. OpenAI, Gemini) to reject or fail to interpret tool definitions.

Solution

  • In �gentkit/tools/schema.py:
    • Retain
      aw_json_schema[$defs] in parameters[$defs] when present.
    • Retain
      aw_json_schema[additionalProperties] in parameters[additionalProperties] when present.
    • Built-in tools without $defs continue producing identical schemas without extra keys.
  • In ests/unit/test_tool_schema.py:
    • Added test validating tools with Enum and nested BaseModel parameters.
    • Added recursive JSON Pointer resolution test asserting that every $ref resolves cleanly inside the emitted schema.
    • Added regression test asserting that built-in tools (calculator,
      ead_file, http_fetch, sql_readonly, web_search) produce expected schemas with no unnecessary keys.

Verification

  • uv run pytest tests/unit/test_tool_schema.py -> 6/6 passed
  • uv run ruff check . -> All checks passed
  • uv run ruff format --check . -> 110 files already formatted
  • uv run mypy agentkit tests/unit/test_tool_schema.py -> Success: no issues found in 43 source files
  • Structural AST lint & Semgrep security check -> Clean

Copilot AI balanced review requested due to automatic review settings October 20, 2026 21:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AUDIT-13 — Medium — Tool JSON schemas drop $defs (unresolvable $ref)

2 participants