Repository navigation
Description
File: mellea/formatters/granite/intrinsics/output.py, DecodeSentences._transform(), lines 714–722
Also relevant: mellea/formatters/granite/intrinsics/input.py, _mark_sentence_boundaries() / _transform()
Commit: c0b163c
Summary
The citations intrinsic crashes with IndexError: list index out of range when the model outputs a sentence index r or c that exceeds the number of sentence boundary markers actually present in the answer/documents. This is expected to be prevented by constrained decoding, but it is not — because the sentence count bounds are computed during input formatting and never propagated into the JSON schema used for constrained decoding.
Root Cause
The citations formatter has two stages.
Input stage (input.py, _mark_sentence_boundaries()): NLTK tokenizes the last assistant message and all documents, inserting <r0>, <r1>, ... and <c0>, <c1>, ... markers. After this runs, the exact sentence counts are known:
rvalid range:[0, n_response_sentences - 1]cvalid range:[0, n_total_doc_sentences - 1](global index across all documents —<c0>.<ck-1>wherek= total sentences across all docs)
These counts are computed locally inside _mark_sentence_boundaries() but are never returned or used further. The index variable that accumulates the total document sentence count is simply discarded.
Schema construction (input.py, __init__()): The structured_outputs schema is set once at construction time from the static io.yaml:
"r": { "minimum": 0, "type": "integer" },
"c": { "items": { "minimum": 0, "type": "integer" }, "type": "array" }No "maximum" is ever set. Constrained decoding therefore enforces only that r and c values are non-negative integers — the upper bound is never provided.
Output stage (output.py, DecodeSentences._transform(), lines 714–722): Indexes into begins/ends/texts using the raw model-output integer with no bounds check:
sentence_num = value
result[self.begin_name] = begins[sentence_num] # IndexError when OOB
result[self.end_name] = ends[sentence_num]
result[self.text_name] = texts[sentence_num]
result[self.document_id_name] = document_ids[sentence_num]Minimal Reproduction (no live model required)
from mellea.formatters.granite.intrinsics.output import _desplit_sentences, DecodeSentences
from unittest.mock import MagicMock
rule = DecodeSentences.__new__(DecodeSentences)
rule.config = {"sentence_boundaries": {"last_message": "r", "documents": "c"},
"instruction": False, "docs_as_message": False}
rule.source = ["last_message"]
rule.begin_name = "response_begin"
rule.end_name = "response_end"
rule.text_name = "response_text"
mock_msg = MagicMock(); mock_msg.content = "<r0> Only one sentence here."
mock_cc = MagicMock(); mock_cc.messages = [mock_msg]; mock_cc.extra_body = None
prepare_output = rule._prepare(MagicMock(), MagicMock(), None, mock_cc)
assert len(prepare_output["begins"]) == 1 # only r=0 exists
rule._transform(1, ("root", 0, "r"), prepare_output)
# → IndexError: list index out of rangeObserved in Production
Intermittently during multi-turn RAG pipelines with top_k=20 retrieved documents. The pipeline completes generation successfully but crashes during citations post-processing.
Activity
planetf1 commentedon Oct 20, 2026
Closing as absorbed by #1719. Its fix item 2 bounds-checks
DecodeSentences, which is exactly this crash site: an out-of-range index becomes aValueErrornaming the index and the sentence count, and a negative index stops silently picking a sentence from the end. The deeper idea from this issue, propagating sentence-count bounds into the constrained-decoding schema so the model can't emit out-of-range indices at all, is deliberately out of scope there. If the newValueErrorstarts firing in practice, please reopen and we'll take the schema route.