Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support parsing primitive values from single-key objects #1224

Merged

Conversation

revidious
Copy link
Contributor

@revidious revidious commented Dec 6, 2024

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.


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).

This description was created by Ellipsis for b4bf23f. It will automatically update as commits are pushed.

- Add support for object-wrapped numbers and booleans\n- Only extract values from simple single-key objects with primitive values\n- Reject nested objects and arrays\n- Add ImpliedKey flag to track extracted field names\n- Add comprehensive test cases
Copy link

vercel bot commented Dec 6, 2024

@revidious is attempting to deploy a commit to the Gloo Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to b4bf23f in 1 minute and 42 seconds

More details
  • Looked at 178 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. engine/baml-lib/jsonish/src/deserializer/coercer/coerce_literal.rs:7
  • Draft comment:
    The use std::vec; statement is unnecessary as the vec! macro is already included in the prelude.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The comment should be placed on the first line of the diff, which is line 7.
2. engine/baml-lib/jsonish/src/deserializer/coercer/coerce_literal.rs:47
  • Draft comment:
    Consider adding a log statement here to indicate that a single-key object is being processed. This can help in debugging and understanding the flow of data.
  • Reason this comment was not posted:
    Confidence changes required: 33%
    The comment should be placed on the first line of the diff, which is line 7.

Workflow ID: wflow_dqxyZ8MpTJD0MMpq


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

vercel bot commented Dec 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 0:21am

Copy link
Contributor

@hellovai hellovai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@hellovai hellovai added this pull request to the merge queue Dec 11, 2024
Merged via the queue into BoundaryML:canary with commit 935a190 Dec 11, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider fixing parsing of literals from objects
3 participants