Skip to content

feat(sdk): wire optional args through python and node bridges#3685

Merged
sxlijin merged 6 commits into
canaryfrom
codex/optional-host-arg-coverage
Jun 4, 2026
Merged

feat(sdk): wire optional args through python and node bridges#3685
sxlijin merged 6 commits into
canaryfrom
codex/optional-host-arg-coverage

Conversation

@sxlijin

@sxlijin sxlijin commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the optional/defaulted host argument coverage spec for Python and TypeScript SDKs.

  • adds observable function_calls fixture coverage for omitted/default/null/value states
  • adds Python baml.UNSET / baml.Unset surface and static rejection checks
  • renders TypeScript defaulted params through a final optional `` object while retaining defineFunction / defineInstanceFunction
  • keeps Python define_function and TypeScript defineFunction barrels in use

Validation

  • cargo check -p sdkgen_typescript_node -p sdkgen_python_pydantic2
  • pnpm --dir /Users/sam/baml2/baml_language/sdks/nodejs/bridge_nodejs exec tsc --noEmit
  • cargo nextest run -p sdk_test_python_pydantic2
  • cargo nextest run -p sdk_test_typescript_node

Summary by CodeRabbit

  • New Features

    • Required-positional vs options-object calling for SDKs; exported stable Unset sentinel; added fixtures exercising single-required and optional-args behaviors.
  • Tests

    • New Python and TypeScript static and runtime tests covering optional args (omitted/None/Unset/undefined), async paths, negative cases, and smoke checks.
  • Bug Fixes

    • Safer delimited protobuf encoding handling in JS runtime.
  • Chores

    • Pyright config and test scaffold tweaks; SDK emission updated to surface per-argument default metadata.

@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jun 4, 2026 7:54pm
new-boundaryml-website Error Error Jun 4, 2026 7:54pm
promptfiddle Ready Ready Preview, Comment Jun 4, 2026 7:54pm
promptfiddle2 Ready Ready Preview, Comment Jun 4, 2026 7:54pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds required-positional + optional-kwargs support and an exported Python Unset sentinel; updates Python and TypeScript emitters and runtimes to split required vs optional params, makes protoc writer usage safer, and adds fixtures plus static/runtime tests covering the new calling semantics.

Changes

Optional arguments feature

Layer / File(s) Summary
End-to-end optional-args and Unset changes
baml_language/sdks/python/src/baml_core/__init__.py, baml_language/sdks/python/rust/sdkgen_python_pydantic2/src/leaf.rs, baml_language/sdks/python/rust/sdkgen_python_pydantic2/src/lib.rs, baml_language/sdks/python/rust/sdkgen_python_pydantic2/src/emit/*, baml_language/sdks/nodejs/bridge_nodejs/typescript_src/define_function.ts, baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js, baml_language/sdks/nodejs/sdkgen_typescript_node/src/*, baml_language/sdk_tests/fixtures/function_calls/baml_src/main.baml, baml_language/sdk_tests/crates/*/function_calls/customizable/*
Introduces exported Unset sentinel and UNSET = Unset(); runtime _split_param_names/_build_kwargs and define_function now accept required vs optional param lists; TypeScript defineFunction/defineInstanceFunction accept required/optional lists and validate options-object shapes; many codegen changes thread per-argument default metadata to emit $opts-backed signatures; protobuf encodeDelimited forks writer when needed; fixtures and tests (Python/TS) added/updated for static and runtime matrices.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • BoundaryML/baml#3476: Prior work on optional/default parameter plumbing and omitted-argument sentinel semantics that this change builds on.

Poem

🐰 I hopped through code with quiet cheer,
Required first, then options near—
Unset stands firm in Python's light,
TypeScript guards make calls polite.
Tests and fixtures nibble joyfully.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main change: wiring optional arguments through both Python and Node.js SDK bridges, which aligns with the PR's core objective of implementing optional/defaulted host-argument support.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/optional-host-arg-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@sxlijin
sxlijin marked this pull request as ready for review June 4, 2026 07:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21e711540e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread baml_language/sdks/nodejs/sdkgen_typescript_node/src/leaf.rs Outdated
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 17.8 MB 7.6 MB file 24.1 MB -6.3 MB (-26.2%) OK
packed-program Linux 🔒 12.9 MB 5.5 MB file 15.1 MB -2.2 MB (-14.6%) OK
baml-cli macOS 🔒 13.6 MB 6.6 MB file 18.2 MB -4.6 MB (-25.5%) OK
packed-program macOS 🔒 9.8 MB 4.8 MB file 11.5 MB -1.7 MB (-14.4%) OK
baml-cli Windows 🔒 14.6 MB 6.7 MB file 19.6 MB -5.0 MB (-25.6%) OK
packed-program Windows 🔒 10.4 MB 4.8 MB file 12.2 MB -1.8 MB (-15.0%) OK
bridge_wasm WASM 11.9 MB 🔒 3.4 MB gzip 3.9 MB -504.8 KB (-13.0%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/sdks/nodejs/sdkgen_typescript_node/src/emit/mod.rs`:
- Line 166: The generated TypeScript function signature emitted by the closure
taking (name, fqn, mode, params, arg_tys, arg_defaults, return_ty) in
emit/mod.rs is missing the proper parameter-name/type list and the explicit cast
for the function type; update that emitter to produce an export like `export
const <name> = defineFunction("<fqn>", "<mode>", [<param names>]) as
(<paramName1>: <type1>, ...) => <return_ty>;` by assembling params with names
and their corresponding types from params and arg_tys, using return_ty for the
RHS cast, and keeping fqn and mode in the defineFunction call so the resulting
line exactly matches the expected form (e.g., `export const extract =
defineFunction("user.lorem.extract", "sync", ["text"]) as (text: string) =>
number;`).

In `@baml_language/sdks/nodejs/sdkgen_typescript_node/src/leaf.rs`:
- Line 826: The func_sym being constructed currently sets arg_defaults:
Vec::new(), which makes all parameters appear optional; instead initialize
arg_defaults with one None entry per parameter to match arity so fn_type_sig
computes required-positional correctly—locate the construction of func_sym (the
struct field arg_defaults in the function that builds func_sym) and replace
Vec::new() with a Vec populated with None for each parameter (e.g., iterating
over the parameters or using params.len()) so the length of arg_defaults equals
the number of parameters.

In `@baml_language/sdks/python/src/baml_core/__init__.py`:
- Around line 162-170: The Unset sentinel is instantiable so callers can create
non-canonical Unset() objects that `_build_kwargs` (which only checks `v is
UNSET`) will not treat as omitted; fix by making Unset a true singleton
(implement `def __new__(cls): if getattr(cls, "_instance", None) is None:
cls._instance = super().__new__(cls); return cls._instance`) so every `Unset()`
returns the same `UNSET` instance, and keep `UNSET = Unset()`; alternatively (or
as a simpler change) update `_build_kwargs` to treat any instance of Unset as
omitted by checking `isinstance(v, Unset)` instead of identity.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 918f31c3-5abf-4a27-930d-ee0af8aec0c6

📥 Commits

Reviewing files that changed from the base of the PR and between 9aa9a80 and 21e7115.

⛔ Files ignored due to path filters (4)
  • baml_language/sdks/nodejs/bridge_nodejs/dist/define_function.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/define_function.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/define_function.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/define_function.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (17)
  • baml_language/sdk_tests/crates/python_pydantic2/function_calls/customizable/optional_args_static.py
  • baml_language/sdk_tests/crates/python_pydantic2/function_calls/customizable/test_main.py
  • baml_language/sdk_tests/crates/python_pydantic2/function_calls/customizable/test_optional_args.py
  • baml_language/sdk_tests/crates/typescript_node/function_calls/customizable/main.test.ts
  • baml_language/sdk_tests/crates/typescript_node/function_calls/customizable/optional_args.static.ts
  • baml_language/sdk_tests/crates/typescript_node/function_calls/customizable/optional_args.test.ts
  • baml_language/sdk_tests/fixtures/function_calls/baml_src/main.baml
  • baml_language/sdk_tests/harness_setup/src/python_pydantic2.rs
  • baml_language/sdk_tests/harness_setup/src/templates/pyproject.toml
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/define_function.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js
  • baml_language/sdks/nodejs/sdkgen_typescript_node/src/emit/function.rs
  • baml_language/sdks/nodejs/sdkgen_typescript_node/src/emit/method.rs
  • baml_language/sdks/nodejs/sdkgen_typescript_node/src/emit/mod.rs
  • baml_language/sdks/nodejs/sdkgen_typescript_node/src/leaf.rs
  • baml_language/sdks/python/rust/sdkgen_python_pydantic2/src/leaf.rs
  • baml_language/sdks/python/src/baml_core/__init__.py

Comment thread baml_language/sdks/nodejs/sdkgen_typescript_node/src/emit/mod.rs
Comment thread baml_language/sdks/nodejs/sdkgen_typescript_node/src/leaf.rs Outdated
Comment thread baml_language/sdks/python/rust/sdkgen_python_pydantic2/src/leaf.rs
Comment thread baml_language/sdks/python/src/baml_core/__init__.py
@sxlijin
sxlijin force-pushed the codex/optional-host-arg-coverage branch from 36bc063 to b609cab Compare June 4, 2026 19:37
@sxlijin sxlijin changed the title [codex] sdk tests: cover optional host args feat(sdk): wire optional args through python and node bridges Jun 4, 2026
@sxlijin
sxlijin enabled auto-merge June 4, 2026 19:43
@sxlijin
sxlijin added this pull request to the merge queue Jun 4, 2026
Merged via the queue into canary with commit bcf8190 Jun 4, 2026
51 checks passed
@sxlijin
sxlijin deleted the codex/optional-host-arg-coverage branch June 4, 2026 19:56
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