fix(client): drop v1-incompat discriminator on InputItem (b48)#814
Merged
scale-ballen merged 1 commit intomainfrom Apr 22, 2026
Merged
fix(client): drop v1-incompat discriminator on InputItem (b48)#814scale-ballen merged 1 commit intomainfrom
scale-ballen merged 1 commit intomainfrom
Conversation
InputItem's __root__ union uses Field(discriminator="type"), but one of its submodels (Item) is itself a RootModel union whose nested submodels don't satisfy pydantic v1 compat's strict discriminator requirements. Under pydantic v2 with v1 compat, class definition fails at import: pydantic.v1.errors.ConfigError: Field 'type' is not the same for all submodels of 'Item' This is the same fix Brandon applied in 1d50898 (feat: support openai 2 in python client), which was wiped out by a subsequent codegen regen. Dropping the discriminator on InputItem makes it a regular Union (try- each validation). Valid data still deserializes into the correct submodel because each has a Literal[...] type field — only the matching submodel validates. JSON input/output is byte-identical. Minimal patch. Other 9 discriminator="type" sites in gen/openai.py are left intact; they don't recursively reference RootModel unions so they don't hit the v1-compat failure. Local verification: - Before: `from llmengine import Completion, Model` raises ConfigError - After: imports cleanly; ChatCompletionV2Request/Response work; all 9 Item submodels import; InputItem/Item/ItemResource/OutputItem1 import; InputMessage instantiation + validation roundtrips Follow-ups: - Fix OpenAPI schema or datamodel-code-generator config so next regen doesn't re-introduce the bug - Add import smoke test to llm-engine CI under pydantic 2 + v1 compat Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lilyz-ai
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Drop
Field(discriminator=\"type\")fromInputItem.__root__ingen/openai.py. Under pydantic v2 + v1 compat, the discriminator on this union triggers:at module-load time, breaking any consumer that imports
llmengine(e.g.egp-api-backend).Background
This is the exact fix @brandon.allen applied in #776 (1d50898 'feat: support openai 2 in python client'). A later commit (bd8a98f 'fix: address python client review feedback') ran codegen which wiped the manual fix. b47 (this repo's main) still carries the bug; b48 re-applies the patch.
Impact
Literal[...]type field, so validation still selects the correct submodel by value.egp-api-backend(the immediate consumer) doesn't useInputItemat all — it only usesCompletionandModel. Zero runtime impact there.Other 9
discriminator=\"type\"sites ingen/openai.pyare left intact; they don't recurse into RootModel unions so they don't hit the v1-compat failure.Local verification
Built wheel, installed into a pydantic==2.11.9 venv (matches egp-api-backend's pin):
from llmengine import Completion, Model→ConfigErrorFollow-ups (separate tickets)
Test plan
🤖 Generated with Claude Code
Greptile Summary
Re-applies the manual fix from #776 that was accidentally reverted by a codegen run: drops
discriminator="type"fromInputItem.__root__becauseItemis itself a__root__-based union (RootModel) and does not expose a uniformtypefield, causing pydantic v1-compat to raiseConfigErrorat module-load time. The version is bumped tob48accordingly. Validation correctness is unaffected; union resolution falls back to sequential try-each instead of O(1) discriminator lookup, which is negligible for typical payloads.Confidence Score: 5/5
Safe to merge — the one-line fix correctly resolves a module-load crash with no JSON or validation regressions.
The change is a targeted, well-understood removal of a pydantic v1-compat incompatible option. The PR description documents root cause, local verification, and downstream impact. The only remaining feedback is a P2 style suggestion to add an explanatory comment/TODO ticket so the next codegen run is easier to catch.
No files require special attention; consider adding the inline comment with a ticket number before the next codegen run to avoid re-introducing the bug.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[InputItem.__root__] --> B{Union resolution} B -->|before fix| C[ConfigError at import\nItem has no uniform type field] B -->|after fix - sequential try-each| D[EasyInputMessage] B -->|after fix - sequential try-each| E[Item - __root__ union\nwith its own discriminator] B -->|after fix - sequential try-each| F[ItemReferenceParam] E --> G[InputMessage / OutputMessage / FileSearchToolCall / ...]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(client): drop v1-incompat discrimina..." | Re-trigger Greptile
Context used:
Learned From
scaleapi/scaleapi#126958
Learned From
scaleapi/scaleapi#126926