Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Support parsing primitive values from single-key objects (#1224)
# Description Fixes #1141 This PR adds support for parsing primitive values from single-key objects in unions. When an LLM responds with an object-wrapped primitive (e.g., `{"status": 1}`), we now correctly extract and validate the inner value. ## Changes - Add support for extracting primitive values (numbers, booleans, strings) from single-key objects - Track the extracted key name using `ImpliedKey` flag - Reject invalid cases: - Nested objects (e.g., `{"status": {"code": 1}}`) - Arrays (e.g., `{"values": [1]}`) - Multi-key objects ## Test Plan Added test cases covering: - Basic object extraction: `{"status": 1}` → `1` - Multiple primitive types in union - Invalid cases (nested objects, arrays) All tests are passing. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Adds support for parsing primitive values from single-key objects in unions, with tests for valid and invalid cases. > > - **Behavior**: > - Supports parsing primitive values from single-key objects in unions in `coerce_literal.rs`. > - Extracts and validates inner values if they are numbers, booleans, or strings. > - Rejects nested objects, arrays, and multi-key objects. > - **Flags**: > - Uses `ImpliedKey` flag to track extracted key names. > - **Tests**: > - Added tests in `test_literals.rs` for basic object extraction, multiple primitive types, and invalid cases (nested objects, arrays). > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for b4bf23f. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Co-authored-by: aaronvg <[email protected]>
- Loading branch information