anthropics / anthropics/anthropic-sdk-go

Tool input_schema quotes encoding/json.Number bounds as strings

Ouverte
#420 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Go
Étoiles
1.2k
Forks
213
Merge moyen
1 j 12 h
PR mergées (30 j)
11

Description

## Problem

The Stainless JSON encoder treats `encoding/json.Number` as a string alias. Tool `input_schema` properties that use stdlib `json.Number` for JSON Schema bounds are serialized as quoted strings:

```json
"minimum":"1","maximum":"9007199254740993"
```

Anthropic-compatible endpoints that validate draft 2020-12 reject the whole tool list (`tools.N.custom.input_schema: JSON schema is invalid`).

This shows up when callers store `minimum` / `maximum` / `exclusiveMinimum` / `exclusiveMaximum` as `encoding/json.Number` (to keep integers above 2^53 exact) and put that map on `ToolInputSchemaParam.Properties`.

Reproduced on v1.66.0 with a `bounded_search` tool whose `page_size` argument uses those bounds.

## Expected

The same values should be JSON numbers (`"minimum":1`) so they match JSON Schema and stay exact (not rounded through `float64`).

The encoder already does this for `internal/encoding/json.Number`. Stdlib `encoding/json.Number` is a different named type, so it misses that branch.

## Workaround today

Put `json.RawMessage` (or `param.SetJSON`) on the properties instead of a Go map that still contains `json.Number`.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Start at the encoder branch that already handles internal/encoding/json.Number and trace serialization of ToolInputSchemaParam.Properties containing stdlib encoding/json.Number. Reproduce the bounded_search case from the issue, then add or run focused coverage to confirm minimum, maximum, exclusiveMinimum, and exclusiveMaximum are emitted as exact JSON numbers and the tool schema is accepted.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
go
Domaine
backend-api-design
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Active
Clarté
Plutôt claire
Accessibilité débutants
72/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.