{"record":{"id":"15b6e0aad43d6e23","repo":"BoundaryML/baml","slug":"details-test-constraints-internal-error","errorCode":null,"errorMessage":"{details} (test constraints internal error)","messagePattern":"(.+?) \\(test constraints internal error\\)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/types/response.rs","lineNumber":430,"sourceCode":"            }\n            (Self::TestFinishReasonFailed(a), Self::TestFinishReasonFailed(b)) => {\n                a.to_string() == b.to_string()\n            }\n            _ => false,\n        }\n    }\n}\n\nimpl Eq for TestFailReason<'_> {}\n\nimpl TestResponse {\n    pub fn status(&self) -> TestStatus<'_> {\n        // Handle expr function response\n        if let Some(expr_res) = &self.expr_function_response {\n            return if expr_res.is_ok() {\n                match self.constraints_result.clone() {\n                    TestConstraintsResult::InternalError { details } => {\n                        TestStatus::Fail(TestFailReason::TestUnspecified(anyhow::anyhow!(details)))\n                    }\n                    TestConstraintsResult::Completed {\n                        checks,\n                        failed_assert,\n                    } => {\n                        let n_failed_checks: usize =\n                            checks.iter().filter(|(_, pass)| !pass).count();\n                        if failed_assert.is_some() || n_failed_checks > 0 {\n                            TestStatus::Fail(TestFailReason::TestConstraintsFailure {\n                                checks,\n                                failed_assert,\n                            })\n                        } else {\n                            TestStatus::Pass\n                        }\n                    }\n                }\n            } else {","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/types/response.rs#L412-L448","documentation":"BAML test runner failed to evaluate the test's constraints (checks/assertions) due to an internal error, so the test is reported as a generic failure with the internal details attached. The library throws this when constraint evaluation itself crashed rather than produced pass/fail check results, and the test harness surfaces it via TestStatus::status() for expr-function tests.","triggerScenarios":"Calling status() on a FunctionResult whose expr_function_response succeeded but whose constraints_result is TestConstraintsResult::InternalError{details}; typically raised during `baml test` runs when a check/assert expression panicked or hit an internal evaluation bug.","commonSituations":"An assert/check clause in a BAML test references a field absent from the parsed output, or a constraint expression throws an unexpected error during evaluation; also seen after BAML version changes where constraint IR shifted.","solutions":["Read the {details} text in the message — it names the internal constraint evaluation error","Check the test's checks/assert clauses for references to fields that may be missing in the function output","Re-run with verbose logging to capture the underlying constraint evaluation panic","Update the BAML CLI/runtime to matching versions and retry"],"exampleFix":"// before\nassert foo.bar == \"x\" {{\n  \"bar must be x\"\n}}\n// after\nassert foo != null && foo.bar == \"x\" {{\n  \"bar must be x (guarded for missing output fields)\"\n}}","handlingStrategy":"try-catch","validationCode":"// before running the test, sanity-check constraint inputs\nconst requiredFields = ['foo'];\nfor (const f of requiredFields) {\n  if (output == null || !(f in output)) throw new Error(`constraint input missing field: ${f}`);\n}","typeGuard":"function hasChecksResult(r) {\n  return r != null && typeof r === 'object' && Array.isArray(r.checks) && r.failed_assert !== undefined;\n}","tryCatchPattern":"try {\n  await runner.runTest(name);\n} catch (e) {\n  if (String(e).includes('test constraints internal error')) {\n    console.error('Constraint evaluation failed:', e.message);\n  }\n  throw e;\n}","preventionTips":["Guard check/assert expressions against null/missing output fields","Keep baml CLI and runtime versions aligned","Run constraint-heavy tests with verbose logging in CI to catch regressions early"],"tags":["testing","constraints","internal-error","rust"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}