Repository navigation
Description
Problem
_parse_batch_support_output in mellea/stdlib/requirements/rag.py stores each judgment under the raw span_id value returned by the model:
span_id = judgment.get("span_id")
...
result[span_id] = support_levelThe caller then looks up results by integer index:
support_level = batch_results.get(idx, "NOT_SUPPORTED")If the model returns span_id as a JSON string (e.g. "span_id": "0") instead of an integer ("span_id": 0), the result is stored under the string key "0", and the integer-keyed lookup misses it — silently falling back to NOT_SUPPORTED even though the model provided a valid assessment.
Reproduction:
from mellea.stdlib.requirements.rag import GroundednessRequirement
req = GroundednessRequirement()
out = '[{"span_id": "0", "support_level": "FULLY_SUPPORTED"}]'
print(req._parse_batch_support_output(out, 1))
# {'0': 'FULLY_SUPPORTED', 0: 'NOT_SUPPORTED'}Impact
Confined to a single GroundednessRequirement.validate() call: one response span silently defaults to NOT_SUPPORTED instead of the model's actual judgment. This can produce a false-negative groundedness verdict (a fully-supported response marked ungrounded) with no exception and no error-level log signal.
Status: unconfirmed trigger
This is a real, verified-by-code-reading and reproducible-in-isolation defect, but I have not observed it occur with a real model. Across ~120 real inference calls against ibm-granite/granite-4.0-micro on GPU hardware (during validation of #1316), span_id was always returned as an unquoted integer, matching the prompt's example format. This is a plausible general LLM-JSON-formatting quirk (small models sometimes quote numeric fields inconsistently), not a confirmed-live bug for this specific model/prompt combination.
Suggested fix
Normalize span_id on both sides of the lookup — e.g. cast to int when parsing (with a guard for non-numeric values), or normalize both the stored key and the lookup key to str.
Related
Found during review of #1316 (batch-support prompt input-key rename), same code path (_parse_batch_support_output).
Activity
psschwei commentedon Sep 3, 2026
This came up when looking at #1618 , so adding it as a comment here in case its relevant:
support_levelhas the same unexpected-type problem asspan_id, but it crashes instead of degrading silently. Both reads call.upper()on the raw value, so a non-string raises an uncaughtAttributeErrorthat escapes theexcept (json.JSONDecodeError, ValueError)and propagates out ofvalidate():Affects both the flat read and
_norm()on the nested path. Also unconfirmed against a real model, same as thespan_idcase.Suggest widening this issue to "normalize model-returned JSON types in
_parse_batch_support_output" and coercing withstr()before.upper()in both places, since thespan_idfix alone won't touch these reads.[-]bug(rag): span_id type mismatch in _parse_batch_support_output silently discards valid judgments[/-][+]bug(rag): normalise model-returned JSON types in RAG requirement parsers[/+]planetf1 commentedon Sep 4, 2026
Broadened scope: normalise model-returned JSON types in both batch support parsing and citation-necessity parsing. This covers quoted numeric span_id values and non-string support_level/needs_citation values, with conservative handling for invalid fields. No live-model e2e test is planned; deterministic parser regressions plus mocked backend-path coverage are sufficient.