Skip to content

Preserve inbound Anthropic PDF documents - #325833

Merged
Bhavya U (bhavyaus) merged 1 commit into
microsoft:mainfrom
AntonioLujanoLuna:fix/anthropic-document-input
Jul 27, 2026
Merged

Bhavya U (bhavyaus) merged 1 commit into
microsoft:mainfrom
AntonioLujanoLuna:fix/anthropic-document-input

Conversation

@AntonioLujanoLuna

Copy link
Copy Markdown
Contributor

Fixes #325672

Summary

  • Preserve base64 PDF document blocks when parsing inbound Anthropic-compatible requests.
  • Preserve PDF documents nested inside tool_result content.
  • Redact base64 document payloads from request logging while retaining their media type.

Problem

The /v1/messages endpoint parses Anthropic request bodies with anthropicMessagesToRawMessages. That converter handled text, images, thinking blocks, tool calls, and tool results, but it did not handle document blocks.

As a result, a top-level PDF was omitted before the request reached the selected model. When a PDF was the only user content, the resulting empty user message could also be omitted entirely. Documents nested inside tool_result content were similarly discarded because only text and image blocks were converted there.

Fix

Base64 Anthropic document sources are now converted to the existing Raw document content part, preserving both the base64 data and application/pdf media type. The same conversion is used for top-level message content and tool-result content.

The downstream Messages and Responses request builders already support Raw PDF document parts, so no endpoint-specific conversion changes are required. The logging conversion now replaces document data with a placeholder, matching the existing image and tool-result sanitization behavior.

Validation

  • npm run gulp compile-extensions
  • npx tsc --noEmit --project tsconfig.json in extensions/copilot
  • npm run test:unit -- src/extension/byok/common/test/anthropicMessageConverter.spec.ts
  • npm run test:unit -- src/platform/endpoint/test/node/messagesApi.spec.ts src/platform/endpoint/node/test/responsesApi.spec.ts
  • npx eslint src/extension/byok/common/anthropicMessageConverter.ts src/extension/byok/common/test/anthropicMessageConverter.spec.ts

The new regression coverage checks top-level PDF documents, documents inside tool results, and logging redaction.

Copilot AI review requested due to automatic review settings July 14, 2026 17:15

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@bhavyaus
Bhavya U (bhavyaus) enabled auto-merge (squash) July 23, 2026 00:48
@bhavyaus
Bhavya U (bhavyaus) force-pushed the fix/anthropic-document-input branch from 1902969 to 73ff3c0 Compare July 27, 2026 18:22
@bhavyaus
Bhavya U (bhavyaus) merged commit 7f590c3 into microsoft:main Jul 27, 2026
29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Jul 27, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

langModelServer silently drops PDF/document blocks from inbound Anthropic requests

5 participants