Skip to content

fix: support ComponentTool deserialization in OpenAI and Azure responses chat generators - #12485

Open
rautaditya2606 wants to merge 1 commit into
deepset-ai:mainfrom
rautaditya2606:fix/responses-chat-generator-tool-deserialization
Open

fix: support ComponentTool deserialization in OpenAI and Azure responses chat generators#12485
rautaditya2606 wants to merge 1 commit into
deepset-ai:mainfrom
rautaditya2606:fix/responses-chat-generator-tool-deserialization

Conversation

@rautaditya2606

Copy link
Copy Markdown
Contributor

Related Issues

Closes #12484

Proposed Changes

  • Updated OpenAIResponsesChatGenerator.from_dict() and AzureOpenAIResponsesChatGenerator.from_dict() to correctly detect serialized Haystack tools using the {"type": ..., "data": ...} serialization envelope instead of matching only "haystack.tools.tool.Tool".
  • Added support for deserializing ComponentTool instances while preserving raw OpenAI tool definitions.
  • Added unit tests covering both serialized Haystack tools and raw OpenAI tools.
  • Added a release note describing the fix.

Root Cause

from_dict() previously determined whether a tool required deserialization using:

tools[0].get("type") == "haystack.tools.tool.Tool"

This fails for ComponentTool, whose serialized representation uses:

{
    "type": "haystack.tools.component_tool.ComponentTool",
    "data": {...}
}

As a result, the serialized dictionary remained in tools instead of being deserialized.

When run() was subsequently called, _prepare_api_call() interpreted the dictionary as a raw OpenAI tool definition and passed the Haystack serialization structure to the OpenAI API, resulting in a 400 Bad Request.

Fix

The implementation now identifies serialized Haystack tools based on the presence of the "data" serialization envelope.

This allows ComponentTool and other serialized Haystack tools to be deserialized correctly while continuing to support raw OpenAI tool definitions such as:

{
    "type": "function",
    ...
}

Reproducer

from haystack.components.builders import PromptBuilder
from haystack.components.generators.chat.openai_responses import OpenAIResponsesChatGenerator
from haystack.tools import ComponentTool

tool = ComponentTool(
    name="prompt",
    description="Builds prompt",
    component=PromptBuilder(template="hi"),
)

generator = OpenAIResponsesChatGenerator(tools=[tool])
data = generator.to_dict()

restored = OpenAIResponsesChatGenerator.from_dict(data)

assert isinstance(restored.tools[0], ComponentTool)

Before the fix:

restored.tools[0] -> dict

After the fix:

restored.tools[0] -> ComponentTool

Tests

Ran the affected test suites:

hatch -e test run pytest \
  test/components/generators/chat/test_openai_responses.py \
  test/components/generators/chat/test_azure_responses.py

Result:

63 passed, 23 skipped in 1.42s

Also ran the newly added tests specifically:

hatch -e test run pytest \
  test/components/generators/chat/test_openai_responses.py \
  test/components/generators/chat/test_azure_responses.py \
  -k "test_from_dict_with_component_tool or test_from_dict_with_raw_openai_tools"

Result:

4 passed, 82 deselected in 0.34s

Checklist

  • Read contributors guidelines and code of conduct
  • Added/updated related issue reference
  • Added unit tests
  • Updated docstrings/documentation where required
  • Added release note
  • Used conventional commit type in PR title
  • Ran pre-commit hooks and fixed reported issues

@rautaditya2606
rautaditya2606 requested a review from a team as a code owner August 27, 2026 08:01
@rautaditya2606
rautaditya2606 requested review from julian-risch and a lite review from Copilot and removed request for a team August 27, 2026 08:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

@rautaditya2606 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@rautaditya2606
rautaditya2606 force-pushed the fix/responses-chat-generator-tool-deserialization branch from cf6fc3e to 290f219 Compare August 27, 2026 08:18
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/generators/chat
  azure_responses.py
  openai_responses.py
Project Total  

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

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.

OpenAI and Azure Responses Chat Generators fail to deserialize ComponentTool

2 participants