Repository navigation
Description
A requirement that fails should tell the repair loop something it can use. Mellea carries that on
ValidationResult.reason, and RepairTemplateStrategy puts it under "The following requirements failed
before" in the retry prompt, which is the only part of that prompt describing the attempt that just
failed.
For a requirement validated by an adapter, that line is the adapter's JSON. The retry is told the score
in a wire format, in the one slot meant to explain what went wrong, while the typed score field built
to carry that number stays empty.
Current behaviour
Validating a requirement runs three steps:
- The adapter scores the output.
requirement-checkanswers with the contract
{"requirement_check": {"score": <float>}}, a number in[0.0, 1.0]where higher means more likely
satisfied. validate()produces a verdict and an explanation. It callsoutput_to_boolfor the pass/fail,
and separately setsreasonfor people and for the repair prompt.ALoraRequirementsupplies
requirement_check_to_boolas that converter
(mellea/stdlib/requirements/requirement.py:110).- The strategy builds the retry. A failed requirement contributes its
reasonto the prompt, and
falls back to the requirement's description only when there is no reason
(mellea/stdlib/sampling/base.py:729-740).
Step 2 is where the explanation and the payload get crossed. validate() assigns the adapter's own
output as the reason (mellea/core/requirement.py:425-430):
judge_output = llm_as_a_judge_result.value
reason = judge_output
if judge_output:
judge_output_str = str(judge_output).strip().lower()
if judge_output_str in ("yes", "no"):
reason = self.descriptionThe substitution fires only for a bare "yes" or "no". The comment above it says why that case
exists: a bare "no" is unhelpful, and the requirement description is more actionable. An adapter's
JSON is neither of those strings, so it survives as the reason verbatim.
flowchart LR
A["requirement_check adapter<br/>JSON payload, score 0.15"] --> B
B["validate()<br/>reason = raw output<br/>score = None"] --> C
C["RepairTemplateStrategy<br/>* {validation.reason}"] --> OUT["retry prompt explains<br/>nothing about the failure"]
classDef graded fill:#cde7cd,stroke:#4a7a4a,color:#111
classDef wrong fill:#f5cfcf,stroke:#a35050,color:#111
classDef plain fill:#d3e2f5,stroke:#48688f,color:#111
class A graded
class B,C wrong
class OUT plain
Problem
Take a requirement described as "State the opening time." and an adapter that scores an attempt at
0.15. The requirement fails, correctly. RepairTemplateStrategy prefers the validation reason over the
requirement description when building the retry feedback (mellea/stdlib/sampling/base.py:729-740), so
rendering the repaired instruction gives the model this:
State the museum's opening time.
Fulfill the following requirements:
* State the opening time.
The following requirements failed before:
* {"requirement_check": {"score": 0.15}}
The retry gains nothing from having failed. The requirement is still there, carried by the
instruction's own requirements block, so nothing has gone missing. But the one block describing the
attempt that just failed offers a key name from mellea's adapter contract and a number the model has no
way to interpret. A generation is spent and no diagnosis is passed on.
Meanwhile the typed field for that number is never filled. score (float | None): Optional numeric score returned by the validator (mellea/core/requirement.py:40), with a public accessor at :75.
No ValidationResult( or PartialValidationResult( call site in production Python passes score=;
the only occurrences of the name are the two __repr__ methods at :122 and :210. So the grade is
present in the result as text the model reads, and absent as a value code can act on. A caller wanting
to auto-approve above 0.9 and send below 0.6 to a human has to re-parse the reason string that was
written for a human, using knowledge of an adapter contract they never called.
The field is already load-bearing, and silently inert. mellea/stdlib/sampling/sofai.py:724
builds its no-improvement signature as (req.description, val.reason, val.score) and compares it
between attempts to decide whether the fast model is making progress. The third element is always
None. A reader of that line would reasonably believe the check compares scores. It cannot, and
nothing says so. What it compares instead is the reason, which happens to contain the score as JSON,
so the comparison works by accident through the wrong field.
And the threshold is not the user's. 0.5 is hardcoded at mellea/stdlib/requirements/requirement.py:62
and documented as fixed at :36 and :43. A safety check that should reject at 0.2 and an editorial
check that should accept at 0.95 get the same midpoint, and changing it means writing your own
output_to_bool.
Reproducer
No GPU and no adapter needed; a stub backend returns what the adapter's contract guarantees it returns.
ADAPTER_OUTPUT = '{"requirement_check": {"score": 0.85}}'
class StubBackend:
async def generate_from_context(self, action, ctx, *, format=None, model_options=None):
return ModelOutputThunk(value=ADAPTER_OUTPUT), ctx
ctx = Mock(spec=Context)
ctx.last_output.return_value = ModelOutputThunk(value="The museum opens at 10:00.")
req = Requirement("Answer is supported.", validation_fn=None,
output_to_bool=requirement_check_to_bool) # what ALoraRequirement wires
r = asyncio.run(req.validate(backend=StubBackend(), ctx=ctx))result bool : True
result.score : None
result.reason : '{"requirement_check": {"score": 0.85}}'
Feeding a failing result (0.15) through RepairTemplateStrategy.repair then gives:
The following requirements failed before:
* {"requirement_check": {"score": 0.15}}
Both scripts are short enough to become tests as they stand.
Proposal
Parse the adapter's output into the fields built for it, rather than passing it through as prose.
validate()setsscorefrom a graded validator, so the number is available as a number.reasonstops carrying machine output. When a converter has produced a structured result, the
reason should be either the requirement description, as the"yes"/"no"branch already does, or a
short rendering a person would want to read, rather than the adapter payload.- The
"yes"/"no"special case becomes the general rule it was reaching for: a reason is for a human
and for the repair prompt, so a machine-readable payload never belongs in it.
flowchart LR
A["adapter output<br/>score 0.15"] --> B
B["validate()<br/>score = 0.15<br/>reason = the requirement"] --> C
C["strategy<br/>repair on the requirement<br/>route on the score"] --> OUT["retry explains the failure<br/>code reads the number"]
classDef graded fill:#cde7cd,stroke:#4a7a4a,color:#111
classDef plain fill:#d3e2f5,stroke:#48688f,color:#111
class A,B graded
class C plain
What changes for a user: the retry prompt names the requirement the output missed instead of a JSON
object, so repair has something to act on. Their code can read result.score and set its own threshold.
A user who only checks bool(result) sees no change, since as_bool() keeps its current meaning and
keeps failing closed.
What this deliberately does not claim. Populating score does not make it trustworthy. Nothing in
mellea has measured whether these adapter scores are calibrated, so a reported 0.7 is not yet evidence
that seven such cases in ten are satisfied. That measurement is worth doing and cannot be done while
the number is only available as text inside a prose field. Carrying it properly is the prerequisite,
not the claim.
Decision needed before implementation: where does the threshold live
Keep 0.5 in requirement_check_to_bool and set score alongside it. Smallest change and it fixes
the reporting and repair-prompt problems immediately. Long-term it leaves the threshold
unconfigurable, so anyone needing a different one still writes their own converter.
Make the threshold a constructor argument on ALoraRequirement. The requirement owns its decision
boundary, which is where a reader looks for it. Long-term this matches how people describe the problem
("reject this one at 0.2"), at the cost of one parameter and a decision about its default.
Return only the score and let strategies threshold. Best fit if strategies grow real routing, but
as_bool() must still answer, so a default has to live somewhere anyway, and the change reaches every
strategy. Today it moves complexity outward for no present consumer.
What to check while doing it
- Do the three graded adapter functions mean the same thing? The axis is comparability.
requirement_checkis satisfaction ("higher = more likely satisfied"),check_certaintyis the
model's certainty about its own response, andguardian_checkis documented as "Risk score as a
float between 0.0 (no risk) and 1.0 (risk detected)" (intrinsic/guardian.py:219-220), so its
direction is inverted. What the user notices if this is glossed over: a threshold meaning "accept
above" for one requirement and "reject above" for another, with nothing in the type to warn them. - What should
reasonsay instead? The axis is repair quality. The description is the safe answer
and matches the existing"yes"/"no"branch. What the user notices: whether the retry prompt
becomes useful or merely stops being JSON. - Does
PartialValidationResultget the same treatment? The axis is streaming parity. It has the
identical unsetscorefield and accessor (:177). What the user notices: per-chunk validation
stays unthresholdable while whole-output validation becomes thresholdable, for no visible reason. - What does a non-adapter validator report? The axis is coverage.
simple_validateand the
plain-Python validators have no natural score, soscorestaysNonefor them. What the user
notices: any code reading it must handle both, which is the honest outcome but should be documented
rather than discovered.
Also in scope
- Fix
sofai.py:724or document it. Either the signature stops including a term that is alwaysNone,
or it genuinely compares scores once they exist. Leaving a constant in a change-detector is
misleading to the next reader either way. - The
ValidationResultdocstring describesscoreas "returned by the validator", which no validator
does. Either the field gets a producer or the docstring stops implying one. - Document that
scoreis populated only by validators that produce one, and that its calibration is
unmeasured.
Related
- bug(strategies): repair/sofai retry prompt receives "no" as failure reason #1497 is the same branch and the same shape: a reason the model cannot use, where mellea substitutes
the description only for a bare"yes"/"no". Worth noting that its wording, "the actual requirement
description is suppressed", overstates the effect in the same way an earlier draft of this issue did.
The description is omitted from the repair block but still rendered by the instruction's requirements
block, so the model does see it. Both issues are about the repair block saying nothing useful, not
about the requirement going missing. They come from one branch and should be fixed together. - bug(strategies): an undetermined validation is repaired as a failed requirement #1673 is the mirror image on the same dataclass:
errorhas no consumer,scorehas no producer.
They can ship in either order, but they interact atsofai.py:724. bug(strategies): an undetermined validation is repaired as a failed requirement #1673 argues sofai escalates on a
broken validator because that signature is byte-identical across attempts when a verdict is
undetermined; that argument survives, since a validator that could not reach a verdict has neither a
score nor a reason. What changes is the signature for genuinely failed verdicts, which today varies
only because the score is smuggled throughreason. Fixing this issue moves that variation into the
field it belongs in, and the escalation trigger should be tested deliberately rather than left to
inherit the accident. - feat: intrinsic-backed Requirement subclass for Guardian safety validation in repair loops #1071 is the Guardian instance of the same gap, and its proposed fix
(ValidationResult(result=score < threshold, ...)) threshold-compares and drops the float exactly as
requirement_check_to_booldoes. If it goes first it should carry the score. - validate should surface parse errors as a third outcome rather than propagating exceptions #1358 (closed) added
errortoValidationResult, the precedent for extending what a validation
result carries rather than widening the boolean. - docs(stdlib): document SamplingResult.sample_generations and sample_validations as stable public API #1499 asks for the
SamplingResultinspection surface to be documented; a per-validation score is
part of what a caller wants from it when an attempt fails. - feat(rag): replace groundedness judgment prompts with the hallucination_detection adapter #1669's
hallucination_detectionadapter returns a four-value categorical rather than a float, so
nothing here blocks or changes that work.
Activity
planetf1 commentedon Oct 5, 2026
Status: root cause confirmed (2026-10-05)
Verified against
mainat4c53add4e. The crossing happens inRequirement.validate(mellea/core/requirement.py:425-430): the judge output is assigned straight toreason, with the description substituting only for a literal "yes"/"no" — the shape LLM-as-a-Judge emits, but not the adapter contract. For an adapter-backed requirement (ALoraRequirement,output_to_bool=requirement_check_to_bool) the judge output is the parsed contract, so a failed check hands the repair prompt's "The following requirements failed before:" slot (mellea/stdlib/sampling/base.py:644) the wire-format JSON{"requirement_check": {"score": 0.2}}— while the typedscorefield onValidationResultstays unset, becauseALoraRequirement.__init__passesvalidation_fn=None(mellea/stdlib/requirements/requirement.py:110, with the live# TODO: ... so that we can set the scoreat :108 pointing at exactly this).Net effect: the retry sees the score in serialised form in the one slot that exists to explain what went wrong, and the field designed to carry the number is empty for every consumer that reads it.
Proposed direction — two parts, different risk:
validate(), when the judge output is a parsed adapter contract carrying a numeric score, setscore=on the result and writereasonas a human sentence ("<description>— adapter score 0.20"). The repair prompt improves for every adapter-backed requirement; no API change.ALoraRequirementsupply avalidation_fnso the typed field is populated at the source for all consumers. That touches theRequirement.validateAPI path and thescoresemantics (is it always the contract's[0.0, 1.0]float, or could a future adapter score on a different scale?), which is why it stays needs-design rather than being rolled into part 1.planetf1 commentedon Oct 20, 2026
Cross-link from #1497, which closes via #1727 with its Part 1 only. Part 2 there proposed making
feedback_strategy="simple"return aNonereason, or defaulting to"first_error". Post-#1727 this is inert on the sofai path (the generic strings are filtered and the description always renders), but two bits survive: the generic reason still reachesRepairTemplateStrategy's failed-requirements block verbatim, and a"first_error"default is an unmeasured quality tradeoff. Both belong in this issue's "what shouldreasonsay" decision rather than as separate work, so recording them here before #1497 auto-closes.planetf1 commentedon Oct 20, 2026
Folded into #1720 as package 3 (repair feedback carries a usable reason), sequenced after #1738 since both touch
Requirement.validate. The proposal, threshold options and reproducer are in the host body. For anyone arriving from #1497 or PR #1727: theRepairTemplateStrategyreason path described here is #1720 package 3.