Commit 7db81c5
authored
feat(anthropic): add validation for arbitrary json objects in structured outputs (#459)
Anthropic models do not support arbitrary JSON objects (e.g. f.json() or f.object() with no properties) in structured outputs. This commit adds a validation step that throws a descriptive error when this unsupported schema is detected, preventing the API from returning a cryptic "Bad Request" error.
For valid structured objects, this commit also ensures `additionalProperties: false` is set recursively, which is required by the Anthropic API.
A new test case has been added to verify the error-throwing behavior.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>1 parent 254bf73 commit 7db81c5
2 files changed
+67
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
59 | 106 | | |
60 | 107 | | |
61 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 33 | + | |
41 | 34 | | |
42 | 35 | | |
43 | 36 | | |
44 | 37 | | |
45 | 38 | | |
46 | 39 | | |
47 | | - | |
48 | | - | |
49 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
65 | | - | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 80 | + | |
83 | 81 | | |
84 | 82 | | |
85 | | - | |
86 | | - | |
87 | | - | |
| 83 | + | |
88 | 84 | | |
89 | 85 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 86 | + | |
93 | 87 | | |
94 | 88 | | |
95 | 89 | | |
| |||
423 | 417 | | |
424 | 418 | | |
425 | 419 | | |
426 | | - | |
| 420 | + | |
427 | 421 | | |
428 | 422 | | |
429 | 423 | | |
| |||
0 commit comments