FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(provider): handle empty content for bedrock/openai-compatible APIs by JackFGreen · Pull Request #17394 · anomalyco/opencode · GitHub

fix(provider): handle empty content for bedrock/openai-compatible APIs - #17394

Closed
JackFGreen wants to merge 1 commit into
anomalyco:devfrom
JackFGreen:fix/bedrock-non-empty
Closed

fix(provider): handle empty content for bedrock/openai-compatible APIs#17394
JackFGreen wants to merge 1 commit into
anomalyco:devfrom
JackFGreen:fix/bedrock-non-empty

Conversation

Copy link
Copy Markdown

Summary

  • Fixes API rejection errors when using AWS Bedrock via openai-compatible provider
  • Transforms empty assistant content ("") to null in openai-compatible requests
  • Extends empty content filtering to openai-compatible provider (previously only Anthropic/Bedrock)
  • Filters empty text blocks from tool-result content arrays
  • Handles tool outputs with empty text but attachments
  • Adds placeholder text [No output] when tool output is completely empty

Background

When using AWS Bedrock (Anthropic models) through the openai-compatible provider, the API rejects assistant messages that have content: "". This typically occurs when an assistant turn has only tool calls but no text response - the AI SDK serializes the content as an empty string, which Bedrock's API rejects.

Changes

  1. Provider-level transformation (packages/opencode/src/provider/provider.ts):

    • Intercepts POST requests for openai-compatible providers
    • Transforms content: "" to content: null for assistant role messages
    • Only modifies messages when needed to avoid unnecessary processing
  2. Message transformation (packages/opencode/src/provider/transform.ts):

    • Extends empty content filtering to @ai-sdk/openai-compatible
    • Filters empty text blocks from nested tool-result content arrays
    • Replaces completely empty tool results with [No output] placeholder
  3. Tool output handling (packages/opencode/src/session/message-v2.ts):

    • Ensures tool results with only attachments don't create empty text blocks
    • Provides fallback placeholder when tool output is completely empty

Testing

Added comprehensive test coverage in:

  • packages/opencode/test/provider/provider.test.ts (3 new tests)
  • packages/opencode/test/provider/transform.test.ts (4 new tests)
  • packages/opencode/test/session/message-v2.test.ts (2 new tests)

All tests verify the transformations work correctly for various edge cases while preserving existing behavior for other providers.

- Transform empty assistant content ("") to null in openai-compatible requests
- Extend empty content filtering to openai-compatible provider
- Filter empty text blocks from tool-result content arrays
- Handle tool outputs with empty text but attachments
- Add placeholder text when tool output is completely empty
- Add comprehensive test coverage for edge cases
github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 13, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potentially related PR:

PR #16750: fix(provider): skip empty-text filtering for assistant messages in normalizeMessages

The other PRs found (Databricks provider support, thinking blocks, dangling tool_use blocks) appear to be less directly related to the core issue of empty content handling for bedrock/openai-compatible providers.

JackFGreen closed this Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL