Skip to content

fix(adapters): only quote string members of Literal in BAMLAdapter schema#10074

Open
nikolauspschuetz wants to merge 1 commit into
stanfordnlp:mainfrom
nikolauspschuetz:fix/baml-adapter-non-string-literals
Open

fix(adapters): only quote string members of Literal in BAMLAdapter schema#10074
nikolauspschuetz wants to merge 1 commit into
stanfordnlp:mainfrom
nikolauspschuetz:fix/baml-adapter-non-string-literals

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

_render_type_str wrapped every Literal member in double quotes, so Literal[1, 2, 3] rendered as "1" or "2" or "3" and Literal[True, False] as "True" or "False" in the schema shown to the LLM. Ints, bools and None are not strings and should render bare; only string members are quoted. Add a regression test covering mixed string/int/bool Literals.

…hema

_render_type_str wrapped every Literal member in double quotes, so
Literal[1, 2, 3] rendered as "1" or "2" or "3" and Literal[True, False]
as "True" or "False" in the schema shown to the LLM. Ints, bools and None
are not strings and should render bare; only string members are quoted.
Add a regression test covering mixed string/int/bool Literals.
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates how BAMLAdapter renders Literal members in schemas. The main changes are:

  • String literal members stay quoted.
  • Integer and boolean literal members render without quotes.
  • A test covers mixed string, integer, and boolean literals.

Confidence Score: 4/5

Mostly safe, with one contained schema-rendering bug to fix.

The main change is small and correct for strings, integers, and booleans. The changed Literal branch still renders None with str(None), which conflicts with the adapter’s JSON null rendering.

dspy/adapters/baml_adapter.py

T-Rex T-Rex Logs

What T-Rex did

  • Ran a focused Python harness to render Literal[None, 'auto'] using the BAMLAdapter, exercising both direct rendering and rendering inside a Pydantic model.
  • Observed that the run output rendered the type as None or 'auto' and the JSON-style expectation of null failed, confirming the adapter emits Python None instead of JSON null.
  • Saved a proof log detailing the command, working directory, pytest output, and exit code for the null-literal regression test.
  • Pytest reported 1 passed in 0.14s with exit code 0, confirming the regression test completed successfully.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
dspy/adapters/baml_adapter.py Updates Literal rendering to quote only string members, but None literals still render as Python None instead of JSON null.
tests/adapters/test_baml_adapter.py Adds tests for string, integer, and boolean literal rendering.

Reviews (1): Last reviewed commit: "fix(adapters): only quote string members..." | Re-trigger Greptile

return " or ".join(f'"{arg}"' for arg in args)
# Only string members are quoted; ints, bools, and None render bare
# so the schema shown to the LLM matches how the value is emitted.
return " or ".join(f'"{arg}"' if isinstance(arg, str) else str(arg) for arg in args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Handle literal nulls
None literals now render as None, while the rest of this schema uses null for absent values (Optional returns or null) and the adapter asks for JSON output. A field like Literal[None, "auto"] would be shown as None or "auto", which does not match the JSON value the model must emit (null) and can mislead the LLM/parser.

Artifacts

Repro: focused Python harness rendering Literal[None, "auto"] with the actual BAMLAdapter code

  • Evidence file captured while the check ran.

Repro: command output showing None in the rendered schema and the failed null expectation

  • The full error output from the failing run.

View artifacts

T-Rex Ran code and verified through T-Rex

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.

1 participant