mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
fix(fireworks): strip non-wire keys from ToolMessage text content blocks (#37187)
Fireworks's chat completions endpoint rejects unknown fields on tool message content blocks — specifically the `id` key that LangChain auto-generates on `TextContentBlock`. Add `_sanitize_chat_completions_content` to strip those extra keys before the payload hits the wire, preventing `Extra inputs are not permitted` errors on tool message round-trips.
This commit is contained in:
@@ -31,6 +31,7 @@ from langchain_fireworks.chat_models import (
|
||||
_convert_dict_to_message,
|
||||
_convert_message_to_dict,
|
||||
_format_message_content,
|
||||
_sanitize_chat_completions_content,
|
||||
_usage_to_metadata,
|
||||
)
|
||||
|
||||
@@ -106,6 +107,32 @@ def test_format_message_content_passthrough_string() -> None:
|
||||
assert _format_message_content("hello") == "hello"
|
||||
|
||||
|
||||
def test_sanitize_chat_completions_text_blocks_strips_id() -> None:
|
||||
"""LangChain auto-generated `id` on text blocks must not reach the wire.
|
||||
|
||||
Fireworks's chat completions schema rejects unknown keys on tool message
|
||||
content blocks (`Extra inputs are not permitted, ... [0].id`).
|
||||
"""
|
||||
message = ToolMessage(
|
||||
content=[{"type": "text", "text": "foo", "id": "lc_abc123"}],
|
||||
tool_call_id="def456",
|
||||
)
|
||||
assert _convert_message_to_dict(message) == {
|
||||
"role": "tool",
|
||||
"content": [{"type": "text", "text": "foo"}],
|
||||
"tool_call_id": "def456",
|
||||
}
|
||||
|
||||
|
||||
def test_sanitize_chat_completions_content_passthrough_string() -> None:
|
||||
assert _sanitize_chat_completions_content("hello") == "hello"
|
||||
|
||||
|
||||
def test_sanitize_chat_completions_content_passthrough_non_text_block() -> None:
|
||||
blocks = [{"type": "image_url", "image_url": {"url": "https://x/y.png"}}]
|
||||
assert _sanitize_chat_completions_content(blocks) == blocks
|
||||
|
||||
|
||||
def test_format_message_content_translates_v1_image_block() -> None:
|
||||
"""Canonical v1 image block is translated to OpenAI image_url + data URI."""
|
||||
blocks = [{"type": "image", "base64": "abc", "mime_type": "image/png"}]
|
||||
|
||||
Reference in New Issue
Block a user