summaryrefslogtreecommitdiffhomepage
path: root/cc/04-schema-debug.md
blob: 58898629aec850b804f56265380eb89ad66bb939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Schema Debug — What zodToJsonSchema Actually Produces

Run this to see what the AI SDK actually sends to Anthropic:

```bash
node --experimental-strip-types -e "
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

const schema = z.object({
    path: z.string().describe('Path to the file, relative to the working directory'),
    offset: z.number().int().min(1).optional().describe('1-indexed start line. Default: 1.'),
    limit: z.number().int().min(1).optional().describe('Max lines to return. Default: 500. Hard cap: 5000.'),
});

console.log(JSON.stringify(zodToJsonSchema(schema), null, 2));
"
```

## Check the @ai-sdk/anthropic adapter's tool serialization

```bash
grep -n 'input_schema\|tools\|jsonSchema\|convertTools' node_modules/@ai-sdk/anthropic/dist/index.mjs | head -30
```

## Check if streamText is receiving the tools correctly

Look at how streamText processes tool options in the AI SDK:

```bash
grep -n 'tools\|toolChoice\|toolCall' node_modules/ai/dist/index.mjs | head -40
```

## Key questions to answer

1. Does `zodToJsonSchema` output `$schema`? If yes, Anthropic may silently reject the tool definition.
2. Does it output `additionalProperties`? Same concern.
3. Does the `@ai-sdk/anthropic` adapter strip these before sending to the API?
4. Does the adapter forward parameter `description` fields from JSON Schema to Anthropic's wire format?
5. Is `tool_choice` being set or defaulting to something suboptimal?