Repository navigation
Conversation
…upported pydantic range
Fixes #2292.
OpenAIChatMessage passed json_schema_input_type to BeforeValidator, but
that argument is only accepted from pydantic 2.9 onwards while the project
declares pydantic>=2.5,<3.0. Importing
nemoguardrails.server.schemas.openai on pydantic 2.5-2.8 therefore raised
TypeError: BeforeValidator.__init__() got an unexpected keyword
argument 'json_schema_input_type'
Build the validator through a small helper that applies the argument when
the installed pydantic supports it and falls back to a plain
BeforeValidator otherwise, so the declared dependency range keeps working.
On pydantic < 2.9 the generated JSON schema describes messages as generic
objects instead of the per-role union; validation behavior is identical.
Verified against pydantic 2.8.2 (fallback path) and 2.13.4 (rich schema
path); reproduction confirmed the TypeError on 2.5.1, 2.6.4, 2.7.4 and
2.8.2 before the change.
Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
Author
|
Closing as part of a contribution-portfolio consolidation: my effort is now focused on a single project (failroute, a static analyzer for silent-failure anti-patterns) and its upstream follow-through. Happy to revisit if there is interest. |
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
Fixes #2292.
OpenAIChatMessagepassedjson_schema_input_typetoBeforeValidator, but that argument is only accepted from pydantic 2.9 onwards, while the project declarespydantic>=2.5,<3.0. Importingnemoguardrails.server.schemas.openaion pydantic 2.5–2.8 therefore raised:This change builds the validator through a small helper that applies the argument when the installed pydantic supports it and falls back to a plain
BeforeValidatorotherwise:On pydantic < 2.9 the generated JSON schema describes
messagesas generic objects instead of the per-role union; runtime validation behavior (stringrolerequired, per-role payload validation) is identical.I kept the declared dependency range as-is rather than bumping the minimum to 2.9, per the issue's "either remove/replace the argument or raise the minimum" — happy to switch to a floor bump + lockfile regeneration if maintainers prefer that route.
Verification
TypeErrorempirically on pydantic 2.5.1, 2.6.4, 2.7.4 and 2.8.2 before the change; confirmed 2.9.2 accepts the argument.tests/server/test_openai_schemas_compat.py:ruff checkandruff format --checkclean with the repo-pinned ruff 0.14.6.AI Disclosure
Per AI_POLICY.md: this pull request was written with AI assistance (ox-alpha coding agent operating on behalf of the submitting human) and reviewed and edited by a human, who verified the changes locally across the pydantic versions listed above. No AI co-author is recorded; the commit is DCO signed by the submitter.