-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Summary
Anthropic's citations feature adds a citations array to text content blocks in responses and streams citations_delta events during streaming. The auto-instrumentation plugin's streaming aggregation drops all citation data because:
citations_deltais not recognized as a delta type — onlytext_deltaandinput_json_deltaare handled- Reconstructed text blocks are built as
{ type: "text", text: accumulated }without preserving anycitationsarray
In non-streaming mode, the full content array passes through extractOutput and citations survive on the text blocks. The gap is specifically in the streaming path.
What instrumentation is missing
Plugin streaming aggregation (js/src/instrumentation/plugins/anthropic-plugin.ts)
In aggregateAnthropicStreamChunks, the content_block_delta handler (lines 174–193) only recognizes:
text_delta→ accumulates textinput_json_delta→ accumulates JSON
citations_delta events are silently ignored. When finalizeContentBlock reconstructs the text block, it creates { ...contentBlock, text: accumulated } — the citations array is never populated.
Vendor types (js/src/vendor-sdk-types/anthropic.ts)
AnthropicStreamEvent's content_block_delta union (lines 112–114) only includes:
{ type: "text_delta"; text: string }{ type: "input_json_delta"; partial_json: string }
Missing: { type: "citations_delta"; citation: { type: string; cited_text: string; document_index: number; ... } }
Wrapper streaming (js/src/wrappers/anthropic.ts)
The wrapper's streamNextProxy also only handles text_delta and input_json_delta in its content_block_delta processing, so citations are lost in the wrapper path as well.
Impact
Users enabling citations on Anthropic documents (plain text, PDFs, custom content) and using streaming will see spans where all citation source references are silently dropped. This affects:
- Document-grounded RAG applications using citations for verification
- Web search tool responses (citations are always enabled for web search results)
- Any workflow relying on citation data for evaluation or debugging
Braintrust docs status
Braintrust Anthropic integration docs do not mention citations (not_found).
Upstream reference
- Anthropic Citations docs: https://platform.claude.com/docs/en/docs/build-with-claude/citations
- Citations are a stable feature, supported on all active models except Haiku 3
- Streaming format:
citations_deltaevents contain individual citation objects to append to the current text block'scitationsarray - Citation types:
char_location,page_location,content_block_location,web_search_result_location cited_textdoes not count toward output tokens
Local files inspected
js/src/instrumentation/plugins/anthropic-plugin.ts(lines 174–193: delta handling, lines 255–302:finalizeContentBlock)js/src/vendor-sdk-types/anthropic.ts(lines 102–122:AnthropicStreamEvent)js/src/wrappers/anthropic.ts(streaming delta handler)e2e/scenarios/anthropic-instrumentation/scenario.impl.mjs(no citations test cases)