Conversation
ImageContext.get_contexts() produced bare-string and non-standard dict
shapes for image_url content blocks, which broke the native OpenAI
adapter (passes blocks through as-is) and only worked with Anthropic
by accident via defensive handling in the translation layer.
- Wrap all image_url values in {"url": ...} dict (OpenAI spec)
- Remove non-standard "format" key from base64 dicts
- Tighten Anthropic translate_image_url_block to require dict input
Fixes #576
Made-with: Cursor
Greptile SummaryThis PR normalizes all
|
| Filename | Overview |
|---|---|
| packages/data-designer-config/src/data_designer/config/models.py | URL path now wraps bare strings in {"url": ...} dict; "format" key removed from base64 dicts since media type is already in the data URI. Return type annotation updated to match. |
| packages/data-designer-engine/src/data_designer/engine/models/clients/adapters/anthropic_translation.py | translate_image_url_block now raises TypeError for non-dict image_url values instead of silently falling back; translate_content_blocks simplified to remove the now-redundant None guard. |
| packages/data-designer-engine/tests/engine/models/clients/test_anthropic_translation.py | Bare-string rejection cases properly extracted into test_translate_image_url_block_rejects_bare_strings using pytest.raises(TypeError), resolving the previous P1 where they were inside a parametrize with expected=None. |
| packages/data-designer-config/tests/config/test_models.py | All URL assertions updated from bare strings to {"url": ...} dicts; "format" key assertions removed. Coverage is thorough across all data_type/auto-detect paths. |
| packages/data-designer-engine/tests/engine/models/clients/test_anthropic.py | Renamed and split tests to clearly distinguish dict-format (valid) from bare-string (invalid) cases; new pytest.raises(TypeError) assertions align with the updated translation layer. |
| packages/data-designer-engine/tests/engine/models/clients/test_openai_compatible.py | Two new passthrough tests verify that OpenAI-compatible client forwards {"url": ...} dicts unchanged for both remote URL and base64 data-URI cases. |
| packages/data-designer-engine/tests/engine/column_generators/generators/test_image.py | Two assertions updated to expect {"url": "https://..."} dict format instead of bare strings, consistent with the rest of the test suite changes. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[ImageContext.get_contexts] --> B{data_type set?}
B -- URL --> C["image_url = {'url': value}"]
B -- BASE64 --> D["image_url = {'url': 'data:image/...;base64,...'}"]
B -- None auto-detect --> E[_auto_resolve_context_value]
E --> F{is file path?}
F -- Yes --> G[load to base64 → _format_base64_context]
F -- No --> H{is URL?}
H -- Yes --> I["return {'url': value}"]
H -- No --> J[_format_base64_context]
G --> K["{'url': 'data:image/...;base64,...'}"]
J --> K
C --> L[OpenAI-compliant block]
D --> L
I --> L
K --> L
L --> M{Adapter?}
M -- OpenAI --> N[Pass through as-is]
M -- Anthropic --> O[translate_image_url_block]
O --> P{image_url is dict?}
P -- No --> Q[raise TypeError]
P -- Yes --> R{data URI?}
R -- Yes --> S[source type=base64]
R -- No --> T[source type=url]
Reviews (3): Last reviewed commit: "address review: tighten return type, add..." | Re-trigger Greptile
Review: PR #577 — fix: normalize image_url blocks to OpenAI-compliant dict formatSummaryThis PR fixes a regression introduced when litellm was removed in v0.5.4.
The OpenAI Chat Completions spec requires The fix:
FindingsCorrectness — LGTM
Concern — Silent drop of legacy bare-string blocks (medium)
If a user (or external code) still constructs messages with bare-string Minor — Stale return-type annotation
Minor — Test name/description driftIn Style / conventions — LGTM
Tests — adequate
Security — no concernsNo changes to auth, input validation at trust boundaries, or credential handling. Data-URI parsing is regex-based and unchanged. Performance — no concernsWrapping a string in a one-key dict is negligible. No new I/O paths. VerdictApprove with minor follow-ups. The core fix is correct and well-tested. Before merging, please consider:
None are blocking. |
translate_image_url_block now raises TypeError when image_url is not a dict. Since all image_url blocks are constructed internally, a bare string indicates an internal bug and should fail loudly. Made-with: Cursor
- Narrow _auto_resolve_context_value return type to dict[str, str] - Add OpenAI-client regression tests for image_url dict passthrough - Cover both bare-URL and bare-data-URI rejection in Anthropic tests Made-with: Cursor
|
Thanks for the thorough review! All three follow-ups addressed in 7e7b26e: Concern — Silent drop → now a hard Nit — Stale return-type annotation Nit — OpenAI-client regression test Bonus — data-URI bare string coverage |
andreatgretel
left a comment
There was a problem hiding this comment.
oops sorry reviewed stale checkout! approved now
📋 Summary
ImageContext.get_contexts()produced bare-string and non-standard dict shapes forimage_urlcontent blocks, which broke the native OpenAI adapter and only worked with Anthropic by accident. This is a regression from the litellm removal in v0.5.4 — litellm was normalizing the shape internally before forwarding to provider APIs.🔗 Related Issue
Fixes #576
🔄 Changes
🐛 Fixed
models.py—data_type=URLpath now wraps value in{"url": ...}instead of passing a bare stringmodels.py— Auto-detect URL path returns{"url": ...}dict instead of bare stringmodels.py— Removed non-standard"format"key from base64 dicts (media type is already encoded in the data URI)🔧 Changed
anthropic_translation.py—translate_image_url_blocknow raisesTypeErrorwhenimage_urlis not a dict (e.g. a bare string). Since allimage_urlblocks are constructed internally by DataDesigner, we control the shape — a malformed block indicates an internal bug and should fail loudly rather than be silently dropped.🧪 Testing
uv run pytestpasses (136 tests across 5 test files)test_completion_rejects_bare_string_image_blocks— verifies Anthropic client raisesTypeErroron bare-stringimage_urltest_translate_content_blocks_rejects_malformed_image_url_block— verifies translation layer raisesTypeErroron malformed blocks✅ Checklist
Made with Cursor