Skip to content

feat: relax OpenAI and HF chat message conversions - #12545

Merged
sjrl merged 8 commits into
mainfrom
fix/openai-converters-allow-contentless-assistant
Sep 2, 2026
Merged

sjrl merged 8 commits into
mainfrom
fix/openai-converters-allow-contentless-assistant

Conversation

@sjrl

@sjrl sjrl commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

  • The OpenAI Chat Completions and Responses converters no longer raise on an assistant message with no content parts, which a Chat Generator returns when it discards a malformed tool call. It is sent with empty content, which the APIs accept, so the next LLM call goes through. ChatMessage.from_openai_dict_format accepts the same empty content, so such a message round-trips.
  • The Hugging Face message converter no longer raises on an assistant message with no content parts, and sends it with empty content instead.

How did you test it?

New tests and expanded existing ones.

Also tested some of the HuggingFace integration components locally to check that their chat templates and models worked with empty assistant messages. E.g.

  • TransformersChatGenerator with HuggingFaceTB/SmolLM2-135M-Instruct worked
  • HuggingFaceAPIChatGenerator with Qwen/Qwen2.5-72B-Instruct and meta-llama/Llama-3.1-8B-Instruct worked

Notes for the reviewer

Integrations that support empty content:

  • watsonx with ibm/granite-4-h-small works. no changes needed since it uses the openai conversion util method
  • litellm with openai/gpt-4.1-nano works. no changes needed since it uses the openai conversion util method
  • cometapi. no changes needed inherits from OpenAIChatGenerator
  • stackit. no changes needed inherits from OpenAIChatGenerator
  • aimlapi. no changes needed inherits from OpenAIChatGenerator

Integrations that support empty content but will need an update:

  • anthropic with claude-opus-5 if we relax the converter
  • ollama with qwen3:0.6b if we relax the converter
  • llama_cpp with Qwen2.5-0.5B-Instruct-GGUF if we relax the converter
  • google gen-ai works if we relax the converter

Integrations that don't support empty content

  • mistral raises a 400 error if the history looks like [user, assistant("")], [user, assistant("Paris is")] or [user, assistant(""), user]
  • perplexity raises a 400 error if the history looks like [user, assistant("")], or [user, assistant(""), user]

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@sjrl sjrl self-assigned this Sep 1, 2026
@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
haystack-docs Ignored Ignored Preview Sep 2, 2026 7:37am UTC

Request Review

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/generators/chat
  openai_responses.py
  haystack/dataclasses
  chat_message.py
  haystack/utils
  hf.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl sjrl changed the title feat: relax openai conversions feat: relax OpenAI and HF chat message conversions Sep 1, 2026
@sjrl sjrl removed their assignment Sep 1, 2026
@sjrl
sjrl marked this pull request as ready for review September 2, 2026 05:47
@sjrl
sjrl requested a review from a team as a code owner September 2, 2026 05:47
@sjrl
sjrl requested review from anakin87 and davidsbatista and removed request for a team and davidsbatista September 2, 2026 05:47
@sjrl

sjrl commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@anakin87 could you review this PR since you already have some context? Also just to let you know I will be opening follow up issues for the integrations that need to be updated.

Update:
Made the issues. You can see them at the bottom of the issue #12541

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the code point of view, it looks good

I'd improve/remove some comments and a test

Comment thread haystack/components/generators/chat/openai_responses.py Outdated
Comment thread haystack/dataclasses/chat_message.py Outdated
Comment thread test/components/agents/test_agent.py Outdated
@sjrl
sjrl merged commit 879d8b0 into main Sep 2, 2026
25 checks passed
@sjrl
sjrl deleted the fix/openai-converters-allow-contentless-assistant branch September 2, 2026 07:57
@julian-risch julian-risch added this to the 3.1.1 milestone Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent crashes on the next LLM call after a Chat Generator discards a malformed tool call

3 participants