Skip to content

feat: extend tool_arg_contract to catch type mismatches (Closes #1528, #1529) - #1531

Merged
Lexus2016 merged 1 commit into
mainfrom
evolution/issue-1529-type-check
Jul 31, 2026
Merged

feat: extend tool_arg_contract to catch type mismatches (Closes #1528, #1529)#1531
Lexus2016 merged 1 commit into
mainfrom
evolution/issue-1529-type-check

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Summary

Extends check_tool_args_contract() in agent/tool_arg_contract.py to validate basic types (string, integer, number, boolean, array, object) against the schema's type declaration, mirroring the existing validate_tool_args() logic in tools/tool_search.py so native tools get the same type guard already available to discovered tools.

Changes

  • agent/tool_arg_contract.py (+75 insertions, -6 deletions):

    • Added ArgContractViolation.type_mismatch() classmethod
    • Added _SCHEMA_PY_TYPES dict and _check_type() helper (mirrors tools.tool_search)
    • Added type-checking loop in check_tool_args_contract() — runs after enum check, validates each present arg against its declared type
    • Updated module docstring to reflect type checking is now included
    • Default-OFF gating unchanged (tool_arg_contract_enabled() not modified)
  • tests/agent/test_tool_arg_contract.py (+104 insertions, 0 deletions):

    • 13 new test cases covering: violation shape, all 6 correct types, 7 parametrized type-mismatch cases (including bool-for-integer edge case), number accepts int, array accepts tuple, union types, unknown-type fail-open, no-type-declaration skip, None skip, combined missing_required + type_mismatch, combined invalid_enum + type_mismatch

#1528 Audit Results

All 8 native tools (terminal, search_files, tool_call, write_file, patch, browser_console, execute_code, process) already have required arrays and type declarations on all properties. No schema fixes needed — all tools are already contract-check compatible.

Design Decisions

  • bool is subclass of int — explicitly rejected for integer params (isinstance(value, int) and not isinstance(value, bool))
  • Fail-open on unknown types — unrecognized type strings return True (don't block dispatch)
  • Union types — value must match at least one variant in a ["string", "integer"] list
  • Dependency-free_SCHEMA_PY_TYPES and _check_type() kept local (not imported from tools.tool_search) to maintain the module's dependency-free design like its siblings agent.verify_policy / agent.policy_interceptors

Line count

185 total changed lines (75+6 + 104+0) — within 200-line self-merge cap.

Checks

  • lint ✓ (ruff check)
  • format ✓ (ruff format)
  • tests ✓ (49 passed — 36 existing + 13 new)

Closes #1528
Closes #1529

Co-Authored-By: Hermes Evolution evolution@hermes.ai

Add basic type checking (string, integer, number, boolean, array, object)
to check_tool_args_contract(), mirroring the existing validate_tool_args()
logic in tools/tool_search.py. Type violations produce ArgContractViolation
with kind='type_mismatch'. Default-OFF gating unchanged.

Also completes #1528 (audit): all 8 native tools already have required arrays
and type declarations — no schema fixes needed.

Closes #1528
Closes #1529

Co-Authored-By: Hermes Evolution <evolution@hermes.ai>
@github-actions github-actions Bot added the bug Something isn't working label Jul 31, 2026
@Lexus2016
Lexus2016 merged commit 6b57215 into main Jul 31, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

1 participant