Commit 5a93b0d
Fix whitespace in JSON keys by trimming during parsing (#1727)
This PR addresses issue #1599 where LLM responses sometimes include JSON
with whitespace around keys (e.g., `" answer "` instead of `"answer"`).
The fix:
1. Modifies the JSON parser to trim whitespace from keys during object
parsing
2. Adds a test case that verifies JSON with whitespace in keys parses
correctly
This ensures that when LLMs return JSON with extra spaces around keys,
the JSON will still be parsed correctly without requiring additional
handling.
Closes #1599
---
🤖 See my steps and cost
[here](https://mentat.ai/agent/506fbbb5-24f5-4c2d-9de4-6fc9a9af4376) ✨
- [x] Wake on any new activity.
---------
Co-authored-by: MentatBot <160964065+MentatBot@users.noreply.github.com>
Co-authored-by: hellovai <vbv@boundaryml.com>1 parent 3ef900a commit 5a93b0d
3 files changed
Lines changed: 57 additions & 1 deletion
File tree
- engine/baml-lib/jsonish/src
- deserializer/coercer/ir_ref
- tests
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
651 | 685 | | |
652 | 686 | | |
653 | 687 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
350 | 372 | | |
351 | 373 | | |
352 | 374 | | |
| |||
0 commit comments