Commit c3e7a53
Yashwant Bezawada
Fix: Strip unsupported JSON Schema keywords for structured outputs
Resolves #2718 where Decimal fields caused 500 errors with responses.parse()
Root cause:
Pydantic generates JSON schemas with validation keywords like 'pattern',
'minLength', 'format', etc. that are not supported by OpenAI's structured
outputs in strict mode. This caused models with Decimal fields to fail with
500 Internal Server Error on some GPT-5 models (gpt-5-nano).
Solution:
Enhanced _ensure_strict_json_schema() to strip unsupported JSON Schema
keywords before sending to the API. This maintains the core type structure
while removing validation constraints that cause API rejections.
Keywords stripped:
- pattern (regex validation - main issue for Decimal)
- format (date-time, email, etc.)
- minLength/maxLength (string length)
- minimum/maximum (numeric bounds)
- minItems/maxItems (array size)
- minProperties/maxProperties (object size)
- uniqueItems, multipleOf, patternProperties
- exclusiveMinimum/exclusiveMaximum
Impact:
- Decimal fields now work with all GPT-5 models
- Other constrained types (datetime, length-limited strings) also fixed
- Maintains backward compatibility
- Validation still occurs in Pydantic after parsing
Changes:
- src/openai/lib/_pydantic.py: Added keyword stripping logic
- tests/lib/test_pydantic.py: Added test for Decimal field handling
Test results:
- Decimal schemas no longer contain 'pattern' keyword
- Schema structure preserved (anyOf with number/string)
- All model types (String, Float, Decimal) generate valid schemas1 parent 6574bcd commit c3e7a53
2 files changed
+95
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
115 | 139 | | |
116 | 140 | | |
117 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
409 | 410 | | |
410 | 411 | | |
411 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
0 commit comments