Skip to content

Fix validation to reject field-level assertions in test blocks#2259

Merged
aaronvg merged 3 commits intoBoundaryML:canaryfrom
dexhorthy:1252-with-research
Aug 5, 2025
Merged

Fix validation to reject field-level assertions in test blocks#2259
aaronvg merged 3 commits intoBoundaryML:canaryfrom
dexhorthy:1252-with-research

Conversation

@dexhorthy
Copy link
Copy Markdown
Contributor

@dexhorthy dexhorthy commented Aug 5, 2025

Summary

Fixes #1252 by adding validation to reject field-level @assert and @check attributes on test blocks. These attributes were previously accepted by the parser but silently ignored at runtime, causing confusion.

Problem

  • BAML tests incorrectly accept @assert (single @) syntax without warnings
  • Field-level assertions on test fields are silently ignored at runtime
  • Only block-level @@assert (double @) assertions actually work for tests
  • This leads to users writing non-functional tests that appear to work

Solution

Added semantic validation in the test validator to:

  1. Check all fields in test blocks for @assert or @check attributes
  2. Emit clear error messages directing users to use @@assert or @@check at the block level instead
  3. Point to the exact location of the invalid attribute

Changes

  • Modified: engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/tests.rs
    • Added validation logic to detect field-level assertion attributes
    • Provides helpful error messages with the correct syntax
  • Added: Test files to verify the validation works correctly
    • field_level_assertions_v2.baml - validates @Assert rejection
    • field_level_check.baml - validates @check rejection

Testing

  • ✅ All existing tests pass
  • ✅ New validation tests pass with expected error messages
  • ✅ No clippy warnings
  • ✅ Error messages point to correct locations

Example Error

error: @assert is not allowed on test fields. Use @@assert at the test block level instead.
  -->  functions_v2/tests/field_level_assertions_v2.baml:9
   |
 8 | test MyTest {
 9 |   functions [TestFunction] @assert({{ true }})
   |

🤖 Generated with Claude Code


Important

Adds validation to reject field-level @assert and @check attributes in test blocks, providing clear error messages and directing users to use block-level assertions.

  • Behavior:
    • Adds validation to reject field-level @assert and @check attributes in test blocks, directing users to use @@assert or @@check at the block level.
    • Provides error messages pointing to the exact location of invalid attributes.
  • Validation Logic:
    • Modified validate() in tests.rs to include logic for detecting field-level assertion attributes.
  • Testing:
    • Added field_level_assertions_v2.baml and field_level_check.baml to test validation of @assert and @check rejection.
    • All existing and new tests pass, ensuring no regression.

This description was created by Ellipsis for 86029cc. You can customize this summary. It will automatically update as commits are pushed.

Add semantic validation to detect and reject @Assert and @check attributes
on test block fields. These field-level assertions are silently ignored at
runtime - only block-level @@Assert and @@check work correctly for tests.

The validation now provides clear error messages directing users to use
the correct block-level syntax instead.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@vercel
Copy link
Copy Markdown

vercel bot commented Aug 5, 2025

@dexhorthy is attempting to deploy a commit to the Boundary Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to 86029cc in 42 seconds. Click for details.
  • Reviewed 362 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/tests.rs:14
  • Draft comment:
    Consider storing attr.name.name() in a local variable to avoid repeated calls (minor performance/clarity improvement).
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. engine/baml-lib/baml/tests/validation_files/functions_v2/tests/field_level_assertions_v2.baml:9
  • Draft comment:
    Test file correctly uses a field-level @Assert to trigger the validation error. The error message format is clear.
  • Reason this comment was not posted:
    Confidence changes required: 10% <= threshold 50% None
3. engine/baml-lib/baml/tests/validation_files/functions_v2/tests/field_level_check.baml:12
  • Draft comment:
    Test file correctly demonstrates rejection of a field-level @check attribute with an appropriate error message.
  • Reason this comment was not posted:
    Confidence changes required: 10% <= threshold 50% None
4. thoughts/2025-08-05_05-15-59_baml_test_assertions.md:72
  • Draft comment:
    Documentation provides a detailed analysis and correctly identifies the validation gap. Ensure the error message in documentation remains consistent with the implementation.
  • Reason this comment was not posted:
    Confidence changes required: 10% <= threshold 50% None
5. thoughts/baml-test-assertion-validation-with-research.md:36
  • Draft comment:
    The implementation plan is comprehensive and clearly outlines success criteria and testing strategy. This helps ensure that the new validation works as intended.
  • Reason this comment was not posted:
    Confidence changes required: 10% <= threshold 50% None

Workflow ID: wflow_TO1UhMd2TYndoEY0

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Keep research docs locally but remove from version control
@dexhorthy
Copy link
Copy Markdown
Contributor Author

ref - #1252

@aaronvg
Copy link
Copy Markdown
Contributor

aaronvg commented Aug 5, 2025

oo thanks, thsi should go out on tonights release

@aaronvg aaronvg enabled auto-merge August 5, 2025 17:33
@aaronvg aaronvg added this pull request to the merge queue Aug 5, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 5, 2025

Codecov Report

❌ Patch coverage is 23.07692% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../validate/validation_pipeline/validations/tests.rs 23.07% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

Merged via the queue into BoundaryML:canary with commit f741e43 Aug 5, 2025
15 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BAML Linter error should occur if user writes one @ in @@assert in a test

2 participants