Skip to content

feat: type coercion for string-typed tool params#62

Open
Simon-Free wants to merge 4 commits intoSafeRL-Lab:mainfrom
Simon-Free:feat-type-coercion
Open

feat: type coercion for string-typed tool params#62
Simon-Free wants to merge 4 commits intoSafeRL-Lab:mainfrom
Simon-Free:feat-type-coercion

Conversation

@Simon-Free
Copy link
Copy Markdown

@Simon-Free Simon-Free commented Apr 21, 2026

feat: type coercion for string-typed tool params

Standalone type coercion module extracted from PR #50.

What it does:

  • Coerces string-typed params sent by LLMs into their schema-declared types
  • "42" becomes 42 for integer, "true" becomes True for boolean, JSON strings become list/dict for array/object

Bug fixes vs original PR #50 bundling:

  • _coerce_bool with garbage input no longer silently returns False - returns original string so tool handler reports the mismatch
  • input_schema-style schemas (Anthropic format) now work - checks both schema.properties and schema.input_schema.properties

Tests: 17 unit tests covering all type coercions, edge cases, and both schema styles.

See also: PR #50 (scheduling + ID uniqueness)

Simon FREYBURGER and others added 4 commits April 17, 2026 18:36
Split _coerce_params (20 lines, nested try/except chain) into:
- a small orchestrator that walks params and delegates,
- four single-purpose coercers (_coerce_int / _coerce_float /
  _coerce_bool / _coerce_json) dispatched through a _COERCERS map.

Each catching coercer still returns the original string on failure -- but
the intent is now explicit via a comment ("tool handler reports the real
type mismatch"), and the bare `except: pass` silent-pass pattern is gone.

Also fix test_scheduling_params_stripped which called execute_tool without
the required config arg; it has been failing since the pr4 branch landed.

Add tests/test_tool_scheduling_e2e.py that drives agent.run with a
mocked LLM:
- assert every schema sent to the stream carries tool_call_alias +
  depends_on (proof the schema injection path is wired through the full
  agent loop, not just a unit helper);
- register a "receiver" tool, let the LLM emit a tool_call with
  scheduling params + one real param, assert the scheduling params are
  gone and the real param reaches the handler.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant