Evaluate baml attribute jinja templates #2477
Closed
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.
Pull Request Template
Thanks for taking the time to fill out this pull request!
Issue Reference
Please link to any related issues
Changes
This PR enables Jinja templating for
@alias
and@description
attributes in BAML, allowing users to inject dynamic content (e.g., environment variables or simple expressions) into these attributes.engine/baml-lib/baml-core/src/ir/walker.rs
to resolve@alias
and@description
attribute strings using Jinja.resolve_attribute_string
to handleStringOr::Value
as Jinja templates,StringOr::JinjaExpression
for direct evaluation, andStringOr::EnvVar
.vars_map()
toengine/baml-lib/baml-types/src/value_expr.rs
to expose environment variables to the Jinja rendering context.Testing
Please describe how you tested these changes
test_attribute_alias_jinja_expression_and_description_template
inengine/baml-runtime/src/internal/prompt_renderer/render_output_format.rs
.cargo test -p baml-runtime --lib
.Screenshots
If applicable, add screenshots to help explain your changes
[Add screenshots here...]
PR Checklist
Please ensure you've completed these items
Additional Notes
To avoid building unrelated workspace members (and their Ruby dependencies), tests were run selectively using
cargo test -p baml-runtime --lib
.[Add any additional notes here...]
Slack Thread