Skip to content

[Bug]: force_string_serializer blanket "deepseek"` substring drops images for vision-capable deepseek-v4.1-flash #5360

Closed

Description

@cbagwell

Is there an existing issue for the same bug?

  • I have searched existing issues and this is not a duplicate.

Bug Description

The SDK silently drops all image content for openhands/deepseek-v4.1-flash
from outgoing requests, even though LLM.vision_is_active() returns True

and the provider can genuinely process images.

This report was drafted by an AI agent (OpenHands) on behalf of the user.

Expected Behavior

A model that the SDK/proxy recognises as vision-capable should serialize image
content with the list serializer. If a model truly requires string-only content,
the SDK should still deliver images via a non-dropping path, or at minimum warn
loudly instead of silently discarding them.

Concretely: deepseek-v4-flash / deepseek-v4.1-flash / deepseek-v4-pro
should not match FORCE_STRING_SERIALIZER_MODELS, since they accept structured
(list) content.

Actual Behavior

Images are removed from the outgoing payload. In this environment the only image
tool observation in the conversation event log contains the base64 image, but the
formatted LLM request contains no image_url part, and the agent reports it can
only see text.

Steps to Reproduce

  1. Use a model whose name contains deepseek and whose provider reports
    supports_vision=True, e.g. openhands/deepseek-v4.1-flash.
  2. Leave force_string_serializer unset (default None).
  3. Format a user message that contains an image:
from openhands.sdk import LLM
from openhands.sdk.llm.message import Message, TextContent, ImageContent

llm = LLM(model="openhands/deepseek-v4.1-flash", api_key="...")  # force_string_serializer defaults to None
msg = Message(
    role="user",
    content=[TextContent(text="What color is this?"), ImageContent(image_urls=["data:image/png;base64,..."])],
)
payload = llm.format_messages_for_llm([msg])

Observed:

vision_is_active()               = True
force_string_serializer (effective) = True   # from "deepseek" substring
image_url parts in payload       = 0
payload = [{"content": "What color is this?", "role": "user"}]

Setting force_string_serializer=False restores it:

force_string_serializer (effective) = False
image_url parts in payload       = 1

The same drop occurs for role="tool" (observation) messages.

Acceptance Criteria

  • A deepseek-named model that reports supports_vision=True no longer has
    its image parts dropped (image_url present in the formatted payload).
  • FORCE_STRING_SERIALIZER_MODELS no longer uses the unqualified "deepseek"
    substring; only the specific legacy ids that genuinely require string-only
    content match.
  • Unit test asserting get_features("openhands/deepseek-v4.1-flash").force_string_serializer is False
    (or that a vision-active model is never string-serialized).
  • Existing DeepSeek-V3.2-Exp string-serializer behavior (PR Add glm4.6 to FORCE_STRING_SERIALIZER #994/Add tests for string serializer #996) is preserved.

Installation Method

pip install openhands-sdk

If you selected "Other", please specify

No response

SDK Version

openhands-sdk==1.49.6 (also present on main at the time of filing: FORCE_STRING_SERIALIZER_MODELS still contains the bare "deepseek" substring).

Version Confirmation

  • I have confirmed this bug exists on the LATEST version of OpenHands SDK

Python Version

3.12

Model Name (if applicable)

openhands/deepseek-v4.1-flash (also reproduced reasoning for deepseek-v4-flash, deepseek-v4-pro). Provider reports supports_vision=True.

Operating System

MacOS

Logs and Error Messages

o error is raised — the image is silently removed. Evidence from
LLM.format_messages_for_llm:

force_string_serializer=None   -> effective=True   images_in_payload=0   # default (bug)
force_string_serializer=False  -> effective=False  images_in_payload=1   # fix
force_string_serializer=True   -> effective=True   images_in_payload=0

Direct provider probe (tool message with list vs. string content) shows the
provider accepts list content, i.e. it does not need the string serializer:

=== deepseek-v4.1-flash ===
  list-content    OK
  string-content  OK
=== deepseek-v4-flash ===
  list-content    OK
  string-content  OK

Minimal Code Sample

from openhands.sdk import LLM
from openhands.sdk.llm.message import Message, TextContent, ImageContent

TINY = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="

def image_parts(fm):
    return sum(1 for m in fm for p in (m.get("content") or [])
               if isinstance(p, dict) and p.get("type") == "image_url")

msg = Message(role="user", content=[TextContent(text="color?"), ImageContent(image_urls=[TINY])])

for v in (None, False):
    llm = LLM(model="openhands/deepseek-v4.1-flash", api_key="x", force_string_serializer=v)
    print(v, "->", image_parts(llm.format_messages_for_llm([msg])))
# None  -> 0   (bug)
# False -> 1   (works)

Screenshots and Additional Context

Introduced by PR #994 / #995 / #996, which moved "deepseek" into the
substring-matched FORCE_STRING_SERIALIZER_MODELS (originally for
DeepSeek-V3.2-Exp). Since then, all DeepSeek models match.

  • Suggested fix: narrow the entry to the specific legacy ids (e.g.
    deepseek-v3, deepseek-v3.2, deepseek-reasoner, deepseek-chat), or skip
    string serialization whenever vision_is_active() is True.
  • Two independent contributing factors for users: (a) the substring match forces
    the flag True; (b) capability_overrides cannot override it, and a None
    field is dropped on profile save (exclude_none=True), so it silently
    reverts to auto-detect.

Related but not the same root cause:


OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

Confirmed bug: FORCE_STRING_SERIALIZER_MODELS in openhands-sdk/openhands/sdk/llm/utils/model_features.py contains the bare substring "deepseek". model_matches() performs an unordered case-insensitive substring test, so every DeepSeek id — including openhands/deepseek-v4.1-flash, deepseek-v4-flash, and deepseek-v4-pro — resolves force_string_serializer=True. In Message.to_chat_dict() the force_string_serializer guard is evaluated before the vision_enabled branch, so the string serializer runs unconditionally and image parts are dropped even when LLM.vision_is_active() is True.

Scope: narrow the DeepSeek entry so only ids that genuinely require string-only tool-message content match, and ensure a vision-active model is never string-serialized. The minimal coherent change is to replace "deepseek" with the specific legacy substring "deepseek-v3.2"; this keeps DeepSeek-V3.2-Exp and deepseek-v3.2-reasoner on the string serializer while freeing v4, v4.1, and deepseek-chat. Because deepseek-v4-flash-vision-exp is a verified DeepSeek id in verified_models.py, the narrowing must also preserve its images.

Non-goals:

  • Do not auto-narrow "glm", "groq/kimi-k2-instruct", or "openrouter/minimax"; no evidence they regress.
  • Do not redesign FORCE_STRING_SERIALIZER_MODELS into per-model feature flags.
  • Do not change capability_overrides / profile exclude_none=True behavior raised in the report; that is a separate concern.
  • Do not add a warning/log when an image is dropped under a forced string serializer unless maintainers request it.

Acceptance Criteria

  • get_features("openhands/deepseek-v4.1-flash").force_string_serializer is False, and the formatted payload for a user message containing ImageContent keeps one image_url part; the same holds for deepseek-v4-flash, deepseek-v4-pro, deepseek-v4-flash-vision-exp, and deepseek-chat.
  • get_features("DeepSeek-V3.2-Exp").force_string_serializer and get_features("deepseek-v3.2-reasoner").force_string_serializer remain True, preserving the behavior introduced by PR Add glm4.6 to FORCE_STRING_SERIALIZER #994/Add tests for string serializer #996.
  • FORCE_STRING_SERIALIZER_MODELS no longer contains the bare "deepseek" substring; the DeepSeek entry matches only the specific legacy id(s) that require string-only content.
  • For a string-serialized model, an ImageContent part is represented in the outgoing payload rather than silently removed (image_url part present or equivalent non-dropping path), for both role="user" and role="tool" messages.
  • An explicit force_string_serializer=True on a vision-capable model still takes precedence and continues to string-serialize without error.
  • Regression coverage exists in tests/sdk/llm/ asserting the above feature-flag and payload outcomes, extending the existing test_force_string_serializer_full_model_names case.
  • Existing DeepSeek-affected unit tests (for example test_llm_force_string_serializer_auto_detect) pass unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions