-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate fieldnames and types when using pydantic codegen #1189
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Reviewed everything up to f4ee739 in 1 minute and 32 seconds
More details
- Looked at
378
lines of code in11
files - Skipped
0
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. engine/baml-lib/baml-core/src/validate/validation_pipeline/validations.rs:31
- Draft comment:
The functionassert_no_reserved_names_in_fields
is called here but is not defined. Did you mean to callassert_no_field_name_collisions
instead? - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable:
The comment is speculative because it assumes the function is undefined without providing evidence. The diff does not show any changes related to the definition ofassert_no_reserved_names_in_fields
, so the comment might not be relevant to the changes made in this diff. Without more context, it's unclear if the function is indeed undefined or if the suggested alternative is correct.
I might be missing the broader context of the codebase where the function could be defined elsewhere. The comment could be valid if the function is indeed undefined, but this cannot be confirmed with the current information.
Given the lack of evidence in the diff and the speculative nature of the comment, it is safer to assume the comment is not useful unless proven otherwise.
Delete the comment as it is speculative and not directly related to the changes in the diff.
2. engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/classes.rs:56
- Draft comment:
The functionassert_no_field_name_collisions
is defined but not used. It seems like it should be called instead ofassert_no_reserved_names_in_fields
invalidations.rs
. - Reason this comment was not posted:
Marked as duplicate.
Workflow ID: wflow_iIwecOoidhbiaDnO
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Incremental review on 2bf8f73 in 15 seconds
More details
- Looked at
13
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
1
drafted comments based on config settings.
1. engine/baml-lib/baml-core/src/validate/validation_pipeline/validations.rs:31
- Draft comment:
Ensure that all references toassert_no_reserved_names_in_fields
are updated toassert_no_field_name_collisions
for consistency. - Reason this comment was not posted:
Confidence changes required:50%
The function name change fromassert_no_reserved_names_in_fields
toassert_no_field_name_collisions
should be reflected in all relevant documentation and comments to maintain consistency.
Workflow ID: wflow_yHwEbIzvM7QTpfe2
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
2bf8f73
to
49d31fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Incremental review on 49d31fb in 22 seconds
More details
- Looked at
271
lines of code in6
files - Skipped
0
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/classes.rs:114
- Draft comment:
Consider directly inserting language keywords into theHashMap
instead of using an intermediateVec
. This will improve performance by reducing unnecessary allocations and iterations. - Reason this comment was not posted:
Confidence changes required:50%
Thereserved_names
function is currently using aVec
to store language keywords, which is then converted to aHashMap
. This can be optimized by directly inserting into theHashMap
without the intermediateVec
. This will improve performance by reducing unnecessary allocations and iterations.
2. engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/classes.rs:90
- Draft comment:
Consider usingunwrap_or_default()
instead ofmap_or("".to_string(), ...)
for better readability and to avoid unnecessary string allocations. - Reason this comment was not posted:
Confidence changes required:50%
Themap_or
function is used with an empty string as the default value. This could be replaced withunwrap_or_default
for better readability and to avoid unnecessary string allocations.
Workflow ID: wflow_BPj7ZLovayyqiTYW
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
Python and pydantic do not allow arbitrary identifiers to be used as fields in classes. This PR adds checks to the BAML grammar, which run conditionally when the user includes a python/pydantic code generator block:
E.g. rule 1:
E.g. rule 2:
These rules are now checked during validation of the syntax tree prior to construction of the IR, and if they are violated we push an error to
Diagnostics
.Bonus: There are a few changes in the PR not related to the issue - they are little cleanups to reduce the number of unnecessary
rustc
warnings.Important
Add validation for field names in BAML classes to prevent Python keyword and type name conflicts when using Pydantic code generation.
assert_no_field_name_collisions()
inclasses.rs
to check field names against Python keywords and type names when using Pydantic.reserved_names()
to map keywords to target languages.new_field_validation_error()
inerror.rs
to acceptString
for error messages.lib.rs
andbuild.rs
to reduce rustc warnings.generator_keywords1.baml
andgenerator_keywords2.baml
to validate new rules.This description was created by for 49d31fb. It will automatically update as commits are pushed.