Skip to content

Commit 070ad26

Browse files
authored
improve error message for asserts and checks (#1975)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Improved error messages for `check` and `assert` constraints in `validate_type_constraints()` in `types.rs`. > > - **Error Messages**: > - Improved error message for `check` constraints in `validate_type_constraints()` in `types.rs` to specify that a valid identifier is required. > - Enhanced error message for `check` and `assert` constraints to clarify the expected format, including examples. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 5f2b0a0. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 0269c3b commit 070ad26

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • engine/baml-lib/baml-core/src/validate/validation_pipeline/validations

engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/types.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,24 @@ fn validate_type_constraints(ctx: &mut Context<'_>, field_type: &FieldType) {
243243

244244
if name.to_string() == "check" {
245245
ctx.push_error(DatamodelError::new_validation_error(
246-
"Check constraints must have a name.",
246+
r#"
247+
Check constraints must have a valid identifier. e.g.:
248+
@check( valid_name_length, {{ this|length > 0 }} )
249+
"#,
247250
span.clone(),
248251
))
249252
}
250253
}
251254
_ => {
252255
ctx.push_error(DatamodelError::new_validation_error(
253-
"A constraint must have one Jinja argument such as {{ expr }}, and optionally one String label",
254-
span.clone()
255-
));
256+
r#"
257+
A check or assert has an optional identifier and a Jinja argument. e.g.:
258+
@check( valid_name_length, {{ this|length > 0 }} )
259+
@assert( {{ this|length > 0 }} )
260+
@assert( valid_name_length, {{ this|length > 0 }} )
261+
"#,
262+
span.clone(),
263+
));
256264
}
257265
}
258266
}

0 commit comments

Comments
 (0)