Skip to content

Processing Utils: continue when content is a string#45605

Merged
zucchini-nlp merged 1 commit intohuggingface:mainfrom
RyanMullins:continue-on-string-content
Apr 23, 2026
Merged

Processing Utils: continue when content is a string#45605
zucchini-nlp merged 1 commit intohuggingface:mainfrom
RyanMullins:continue-on-string-content

Conversation

@RyanMullins
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes crash for the following messages structure when calling

processor = AutoProcessor.from_pretrained(model_id)
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": [{"type": "text", "text": "Write a short joke about saving RAM."}]},
]
processor.apply_chat_template(messages, tokenize=True)
Traceback (most recent call last):
  File "$HOME/git/transformers/local_testing/assisted_generation.py", line 18, in <module>
    inputs = processor.apply_chat_template(
        messages,
    ...<4 lines>...
        enable_thinking=False,
    )
  File "$HOME/git/transformers/src/transformers/processing_utils.py", line 1822, in apply_chat_template
    content_block for content_block in content if content_block["type"] in ["image", "video"]
                                                  ~~~~~~~~~~~~~^^^^^^^^
TypeError: string indices must be integers, not 'str'

Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.

PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.

This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read CONTRIBUTING.md.

  • I confirm that this is not a pure code agent PR.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@zucchini-nlp

@zucchini-nlp zucchini-nlp enabled auto-merge April 23, 2026 14:18
@zucchini-nlp zucchini-nlp added this pull request to the merge queue Apr 23, 2026
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Merged via the queue into huggingface:main with commit 1e071b2 Apr 23, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants