Skip to content

fix: make FunctionParameters and LogitBias OpenAI-compatible#1039

Merged
markstur merged 5 commits into
generative-computing:mainfrom
markstur:fix/issue-971
May 12, 2026
Merged

fix: make FunctionParameters and LogitBias OpenAI-compatible#1039
markstur merged 5 commits into
generative-computing:mainfrom
markstur:fix/issue-971

Conversation

@markstur

@markstur markstur commented May 7, 2026

Copy link
Copy Markdown
Contributor

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

fix: make FunctionParameters and LogitBias OpenAI-compatible

Use Pydantic's RootModel to accept bare JSON Schema dicts instead of
requiring a non-standard RootModel wrapper field. This makes m serve
compatible with standard OpenAI clients.

BREAKING CHANGE: FunctionParameters(RootModel={...}) is now FunctionParameters({...})

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Attribution

  • AI coding assistants used

@markstur markstur requested a review from a team as a code owner May 7, 2026 20:23
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

The PR description has been updated. Please fill out the template for your PR to be reviewed.

@markstur markstur changed the title Fix/issue 971 fix: make FunctionParameters and LogitBias OpenAI-compatible May 7, 2026
@github-actions github-actions Bot added the bug Something isn't working label May 7, 2026
@markstur

markstur commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@planetf1 don't want to assign you work but fyi this is an issue raised from your feedback

@markstur markstur force-pushed the fix/issue-971 branch 2 times, most recently from 272960a to f0fc46b Compare May 7, 2026 22:19
Comment thread cli/serve/models.py Outdated
@planetf1

Copy link
Copy Markdown
Contributor

The core fix looks solid — switching FunctionParameters and LogitBias to RootModel[dict] is exactly right, and the test updates follow through consistently. Left a few notes below: one thing worth sorting before this lands, and a couple of minor observations that are fine to pick up in a follow-up if you'd rather keep this focused.

Comment thread cli/serve/models.py
@planetf1

Copy link
Copy Markdown
Contributor

Minor / non-blocking: small gotcha with the alias — Field(alias="schema") means .model_dump() emits schema_ (the Python attribute name), not schema:

j = JsonSchemaFormat(name="test", schema={"type": "object"})
j.model_dump()
# → {"name": "test", "schema_": {"type": "object"}}

For the current code path — where json_schema.schema_ is only read internally — this is harmless. But if it ever gets serialised and sent anywhere (a client, a log), the wrong key comes out. Worth either using .model_dump(by_alias=True) at the call site, or adding "serialize_by_alias": True to model_config to make it the default. Fine to leave for a follow-up.

@planetf1

Copy link
Copy Markdown
Contributor

Minor / non-blocking: one gap worth noting in the test coverage — there's no HTTP-layer test that sends the old {"RootModel": {...}} payload to /v1/chat/completions and confirms it gets a sensible error back. Given this is a breaking API change, a short TestClient test for the legacy envelope format would make the regression boundary explicit. Totally fine as a follow-up if you'd rather keep this PR focused.

@planetf1 planetf1 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.

One issue worth sorting before this lands — the silent {"RootModel": {...}} pass-through on FunctionParameters (see inline comment). For a breaking API change, clients that haven't updated yet deserving a clear error rather than a confusing inference failure downstream.

The other comments are minor and non-blocking.

@markstur markstur requested a review from planetf1 May 11, 2026 22:31

@planetf1 planetf1 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.

Both issues addressed — happy with the validator approach and the LogitBias cleanup. LGTM.

@markstur markstur enabled auto-merge May 12, 2026 15:28
markstur added 5 commits May 12, 2026 08:41
Use Pydantic's RootModel to accept bare JSON Schema dicts instead of
requiring a non-standard RootModel wrapper field. This makes m serve
compatible with standard OpenAI clients.

BREAKING CHANGE: FunctionParameters(RootModel={...}) is now FunctionParameters({...})

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Assisted-by: IBM Bob
Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
The updated bare dict for OpenAI API compatibility would still
accept a key named RootModel, but the behavior would be wrong.
To assist in migration add validation and reject the legacy
wrapper.

BREAKING CHANGE: FunctionParameters validator now rejects {"RootModel": {...}}
envelope pattern. Send parameters as bare JSON Schema objects instead.

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Assisted-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Add serialize_by_alias=True to JsonSchemaFormat.model_config to ensure
schema_ field serializes as "schema" not "schema_" for OpenAI compatibility.
Add test coverage for serialization behavior.

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Assisted-by: IBM Bob
@markstur markstur added this pull request to the merge queue May 12, 2026
Merged via the queue into generative-computing:main with commit 933b71a May 12, 2026
8 checks passed
@markstur markstur deleted the fix/issue-971 branch May 12, 2026 16:59
akihikokuroda pushed a commit to akihikokuroda/mellea that referenced this pull request May 27, 2026
…ive-computing#1039)

* fix: make FunctionParameters and LogitBias OpenAI-compatible

Use Pydantic's RootModel to accept bare JSON Schema dicts instead of
requiring a non-standard RootModel wrapper field. This makes m serve
compatible with standard OpenAI clients.

BREAKING CHANGE: FunctionParameters(RootModel={...}) is now FunctionParameters({...})

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Assisted-by: IBM Bob

* test(cli): update tests and example removing RootModel

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>

* chore: remove unused LogitBias model

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>

* feat!: reject legacy RootModel envelope in function parameters

The updated bare dict for OpenAI API compatibility would still
accept a key named RootModel, but the behavior would be wrong.
To assist in migration add validation and reject the legacy
wrapper.

BREAKING CHANGE: FunctionParameters validator now rejects {"RootModel": {...}}
envelope pattern. Send parameters as bare JSON Schema objects instead.

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Assisted-by: Mark Sturdevant <mark.sturdevant@ibm.com>

* fix(serve): serialize JsonSchemaFormat with 'schema' alias

Add serialize_by_alias=True to JsonSchemaFormat.model_config to ensure
schema_ field serializes as "schema" not "schema_" for OpenAI compatibility.
Add test coverage for serialization behavior.

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Assisted-by: IBM Bob

---------

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

This "RootModel" key is non-standard and will cause any real OpenAI-compatible client to fail.

2 participants