Skip to content

Surface page and content-block citation regions from Anthropic - #1099

Merged
Quim Muntal (qmuntal) merged 1 commit into
microsoft:mainfrom
PratikDhanaveFork:fix/anthropic-page-block-citation-regions
Sep 18, 2026
Merged

Quim Muntal (qmuntal) merged 1 commit into
microsoft:mainfrom
PratikDhanaveFork:fix/anthropic-page-block-citation-regions

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

Anthropic citations report the cited span in one of three ways depending on the source: character offsets (char_location), PDF page numbers (page_location), or content-block indices (content_block_location). citationAnnotations only built a TextSpanAnnotatedRegion for char_location, so page- and block-located citations arrived with no region data even though the SDK TextCitationUnion exposes StartPageNumber/EndPageNumber and StartBlockIndex/EndBlockIndex.

This mirrors the Python client (_parse_citations_from_anthropic), which builds a TextSpanRegion for each of the three location types.

Change

  • Map page_location (page numbers) and content_block_location (block indices) to a text-span region, alongside the existing char_location handling.

Both the streaming and non-streaming paths route citations through citationAnnotations, so both are fixed.

Tests

  • TestPageLocationCitationsBecomeAnnotatedRegions and TestContentBlockLocationCitationsBecomeAnnotatedRegions: assert the region indices are surfaced. Both fail before the change (AnnotatedRegions is nil), pass after.

citationAnnotations only built a text-span region for char_location
citations, so page_location and content_block_location citations lost their
region data (start/end page number and start/end block index respectively).

Map all three location types to a text-span region, matching the Python
client which builds a TextSpanRegion for each. Both the streaming and
non-streaming paths route citations through this helper, so both benefit.
Copilot AI lite review requested due to automatic review settings September 18, 2026 11:20
@github-actions github-actions Bot added area:provider Changes files in the provider area area:provider/anthropic Changes files in the provider / anthropic area size:medium At most 100 changed lines across at most 5 files labels Sep 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes and tests are complete with no unresolved review issues.

Pull request overview

Adds support for Anthropic page-based and content-block-based citation regions.

Changes:

  • Maps page numbers and block indices to annotated regions.
  • Adds tests for both citation types.
File summaries
File Description
provider/anthropicprovider/agent.go Adds region mapping for page and content-block citations.
provider/anthropicprovider/agent_test.go Tests the new citation region behavior.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot added kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure labels Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Scope: user-visible behavior (bug fix; no exported API change)
Changed Go contract: citationAnnotations (unexported helper in provider/anthropicprovider/agent.go) now maps page_location and content_block_location Anthropic citation types to a message.TextSpanAnnotatedRegion, in addition to the existing char_location handling. message.CitationAnnotation.AnnotatedRegions is populated for all three cases; no new exported types, fields, or methods are introduced.
Upstream evidence reviewed: python/packages/anthropic/agent_framework_anthropic/_chat_client.py, method _parse_citations_from_anthropic (around lines 1659-1707). For char_location, page_location, and content_block_location, the Python client builds a TextSpanRegion(type="text_span", start_index=..., end_index=...) using start_char_index/end_char_index, start_page_number/end_page_number, and start_block_index/end_block_index respectively — the same three cases and field mappings this PR adds to Go. Tests in python/packages/anthropic/tests/test_anthropic_client.py (around lines 4061-4161) exercise all three location types.
Result: aligned. This restores parity with the existing Python behavior rather than introducing new semantics — the Go implementation previously only handled char_location and silently dropped region data for page_location/content_block_location, which was the actual divergence. The fix brings Go in line with Python's TextSpanRegion mapping for all three citation location types. The change touches only an unexported helper and adds tests; no exported Go API surface changed, so public-api-change is not applicable.

Generated by Go API Consistency Review Agent · copilot · auto · 28.2 AIC · ⌖ 5.17 AIC · ⊞ 9.2K ·

@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Sep 18, 2026
Merged via the queue into microsoft:main with commit 10d7915 Sep 18, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider/anthropic Changes files in the provider / anthropic area area:provider Changes files in the provider area kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure size:medium At most 100 changed lines across at most 5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants