Commit f36f85e
authored
fix(ai-sdk): keep output validation enabled for tool procedures (#1791)
`createToolFactory` disabled both input and output validation on the
assumption that the AI SDK re-validates against the tool schemas. That
is only true for input: the AI SDK treats `outputSchema` as type
metadata and never validates the value `execute` returns against it
(confirmed in
[vercel/ai#10222](vercel/ai#10222), docs
corrected in
[vercel/ai#11016](vercel/ai#11016)). Procedures
run as tools therefore skipped their `.output()` schemas entirely,
including transforms and defaults.
## Fixes
- Output validation stays enabled; only input validation remains
disabled, since that half is genuinely redundant.
- A handler returning invalid output now rejects with an output
validation error instead of passing through silently.
- Streamed `asyncIteratorObject` outputs validate every yielded event,
and a handler returning a non-iterator now errors instead of being
yielded once as the final result (the old fallback branch became
unreachable and is removed).
## Testing
- A new `generateText` test with a mock model proves the AI SDK returns
schema-violating `execute` output untouched, so it will start failing if
a future `ai` release adds output validation and makes ours redundant.
- Remaining tests cover input validation being skipped, invalid output
rejection, per-event stream validation, and non-iterator rejection.1 parent 9f9d664 commit f36f85e
2 files changed
Lines changed: 76 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
204 | 239 | | |
205 | 240 | | |
206 | 241 | | |
| |||
275 | 310 | | |
276 | 311 | | |
277 | 312 | | |
278 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
279 | 329 | | |
280 | 330 | | |
281 | 331 | | |
282 | | - | |
| 332 | + | |
283 | 333 | | |
284 | 334 | | |
285 | 335 | | |
286 | | - | |
| 336 | + | |
287 | 337 | | |
288 | 338 | | |
289 | 339 | | |
| |||
335 | 385 | | |
336 | 386 | | |
337 | 387 | | |
338 | | - | |
| 388 | + | |
339 | 389 | | |
340 | 390 | | |
341 | 391 | | |
342 | 392 | | |
343 | 393 | | |
344 | 394 | | |
345 | 395 | | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
350 | 408 | | |
351 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
352 | 414 | | |
353 | 415 | | |
354 | 416 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
266 | 268 | | |
267 | 269 | | |
268 | 270 | | |
269 | 271 | | |
270 | | - | |
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
| |||
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
| 285 | + | |
292 | 286 | | |
293 | 287 | | |
294 | 288 | | |
| |||
0 commit comments