Skip to content

fix: ImageContext produces non-compliant image_url blocks for OpenAI and Anthropic APIs #576

@nabinchha

Description

@nabinchha

Description

ImageContext.get_contexts() produces image_url content blocks that are non-compliant with both the OpenAI and Anthropic vision APIs. This is a regression introduced after the removal of litellm in v0.5.4 — litellm was likely normalizing the shape internally before forwarding to provider APIs, which masked the issue.

Problem

Three code paths in ImageContext.get_contexts() produce incorrect shapes:

Code path Current image_url value OpenAI-valid? Anthropic-valid?
data_type=URL bare string "https://..." No Yes (adapter handles it)
data_type=BASE64 {"url": "data:...", "format": "png"} No (format is non-standard) Yes
Auto-detect URL bare string "https://..." No Yes (adapter handles it)

The OpenAI vision API expects:

{"type": "image_url", "image_url": {"url": "https://..."}}

The Anthropic adapter's translate_image_url_block defensively handled both bare strings and dicts, so Anthropic worked by accident. But the OpenAI native adapter passes content blocks through as-is, so multimodal requests with image URLs fail.

Fix

  • Always wrap image_url values in {"url": ...} dict format (matches OpenAI spec)
  • Remove non-standard "format" key from base64 dicts (media type is already encoded in the data URI)
  • Tighten the Anthropic adapter's translate_image_url_block to raise TypeError when image_url is not a dict. Since all image_url blocks are constructed internally by DataDesigner (not by end users), a malformed block indicates an internal bug and should fail loudly rather than be silently dropped.

Files affected

  • packages/data-designer-config/src/data_designer/config/models.pyImageContext.get_contexts(), _auto_resolve_context_value(), _format_base64_context()
  • packages/data-designer-engine/src/data_designer/engine/models/clients/adapters/anthropic_translation.pytranslate_image_url_block()
  • Test files in both data-designer-config and data-designer-engine

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingin-progressAgent is actively buildingtriagedIssue reviewed and approved by a maintainer

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions