Skip to content

Bug: response_end span in granite33 uses full response length instead of sentence length #843

Closed

Description

@psschwei

This was flagged as worthy of followup when reviewing #818 :

In granite33/output.py:226 — The line computes:

citation["response_end"] = index + len(response_text_without_citations)

  • response_text is the individual sentence associated with this citation (looked up from response_sents_by_citation_id)
  • response_text_without_citations is the entire response with all citation tags stripped
  • index is where the individual sentence starts within the full response

So response_end ends up being (start of sentence) + (length of entire response), which will always overshoot past the end of the actual sentence — potentially past the end of the string entirely.

The correct formula should be:

citation["response_end"] = index + len(response_text)

The granite32 version does this correctly:

citation["response_end"] = last_response_text_match["begin_idx"] + len(
response_text
)

Impact: Every citation span in granite 3.3 output will have a response_end that points to roughly the end of the full response rather than the end of the cited sentence. Downstream consumers that slice response[begin:end] would get a much larger substring than intended.

Activity

  1. added
    bug
    on Apr 13, 2026
  2. added theissue type on Apr 13, 2026
  3. planetf1 commented on Apr 13, 2026

    @planetf1
    Contributor

    Fix reference for agents:

    mellea/formatters/granite/granite3/granite33/output.py:227 — change:

    citation["response_end"] = index + len(response_text_without_citations)

    to:

    citation["response_end"] = index + len(response_text)

    The granite32 equivalent at granite3/granite32/output.py:292-293 is correct and can be used as reference. Add a regression test in test/formatters/granite/test_granite33_output.py.

  4. self-assigned this
    on Apr 13, 2026
  5. added 3 commits that reference this issue on Apr 13, 2026
    1d67bd2
    7d4fabb
    8e2472f
  6. added a commit that references this issue on Apr 16, 2026
    06d1dbb
  7. added a commit that references this issue on May 27, 2026
    fed6278
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions