Skip to content

bug(rag): normalise model-returned JSON types in RAG requirement parsers #1614

Closed

Description

@planetf1

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_level

The 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

  1. added
    bug
    on Sep 3, 2026
  2. psschwei commented on Sep 3, 2026

    @psschwei
    Contributor

    This came up when looking at #1618 , so adding it as a comment here in case its relevant:

    support_level has the same unexpected-type problem as span_id, but it crashes instead of degrading silently. Both reads call .upper() on the raw value, so a non-string raises an uncaught AttributeError that escapes the except (json.JSONDecodeError, ValueError) and propagates out of validate():

    from mellea.stdlib.requirements.rag import GroundednessRequirement
    req = GroundednessRequirement()
    
    req._parse_batch_support_output('[{"span_id": 0, "support_level": 5}]', 1)
    # AttributeError: 'int' object has no attribute 'upper'
    
    req._parse_batch_support_output('[{"span_id": 0, "evidence": [{"support_level": 5}]}]', 1)
    # AttributeError: 'int' object has no attribute 'upper'

    Affects both the flat read and _norm() on the nested path. Also unconfirmed against a real model, same as the span_id case.

    Suggest widening this issue to "normalize model-returned JSON types in _parse_batch_support_output" and coercing with str() before .upper() in both places, since the span_id fix alone won't touch these reads.

  3. self-assigned this
    on Sep 4, 2026
  4. changed the title [-]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[/+] on Sep 4, 2026
  5. added
    p2
    on Sep 4, 2026
  6. planetf1 commented on Sep 4, 2026

    @planetf1
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugp2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions