Skip to content

fix(anthropic): preserve canonical tool JSON#186

Merged
raphael merged 1 commit into
mainfrom
agent/preserve-anthropic-tool-json
Jul 18, 2026
Merged

fix(anthropic): preserve canonical tool JSON#186
raphael merged 1 commit into
mainfrom
agent/preserve-anthropic-tool-json

Conversation

@raphael

@raphael raphael commented Jul 18, 2026

Copy link
Copy Markdown
Member

Summary

  • decode Anthropic tool schemas and examples as top-level raw JSON fields
  • preserve nested numbers and large integers exactly through the Anthropic SDK encoder
  • consolidate overlapping implementation tests into a provider wire-level regression test

Rationale

The Anthropic SDK uses a custom reflection-based JSON encoder. Although json.Decoder.UseNumber prevents float64 precision loss, the SDK observes json.Number as a string-backed type and serializes values such as 2 as "2". Numeric tool examples then contradict their JSON schemas and can cause repeated model tool-call failures.

The adapter now materializes only the object envelope required by the SDK and retains each field as json.RawMessage. This is simpler than recursively rewriting decoded values and preserves the canonical schema and example JSON verbatim.

Impact

Anthropic requests now send tool schema constraints and provider-native input examples with their authored JSON types and numeric precision. This improves tool-call correctness without changing the goa-ai tool contract or other provider adapters.

Validation

  • go test ./features/model/anthropic
  • make lint

@raphael
raphael marked this pull request as ready for review July 18, 2026 23:48
@raphael
raphael merged commit f2a3722 into main Jul 18, 2026
2 checks passed
@raphael
raphael deleted the agent/preserve-anthropic-tool-json branch July 18, 2026 23:51
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