langchain - ✅(Solved) Fix `_construct_responses_api_input` omits type: "message" on user/system/developer items, breaking Foundry Responses API Body: [4 pull requests, 5 comments, 6 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35688Fetched 2026-04-08 00:25:10
View on GitHub
Comments
5
Participants
6
Timeline
20
Reactions
0
Author
Assignees
Timeline (top)
commented ×5cross-referenced ×4labeled ×3mentioned ×2

_construct_responses_api_input() in langchain_openai/chat_models/base.py builds Responses API input items without explicitly setting "type": "message" on user, system, and developer message dicts. OpenAI's native endpoint silently infers the type, but other OpenAI-compatible endpoints (e.g. Microsoft Foundry) enforce the schema strictly and reject the request with a 400 Bad Request.

Error Message

BadRequestError: Error code: 400 - {'error': {'message': "Invalid value: ''. Supported values are: 'apply_patch_call', ..., 'message', ..., and 'web_search_call'.", 'type': 'invalid_request_error', 'param': 'input[1]', 'code': 'invalid_value'}}

Root Cause

_construct_responses_api_input() in langchain_openai/chat_models/base.py builds Responses API input items without explicitly setting "type": "message" on user, system, and developer message dicts. OpenAI's native endpoint silently infers the type, but other OpenAI-compatible endpoints (e.g. Microsoft Foundry) enforce the schema strictly and reject the request with a 400 Bad Request.

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
BadRequestError: Error code: 400 - {'error': {'message': "Invalid value: ''. Supported values are: 
'apply_patch_call', ..., 'message', ..., and 'web_search_call'.",
'type': 'invalid_request_error', 'param': 'input[1]', 'code': 'invalid_value'}}

Other Dependencies

aiohttp: 3.13.3 azure-ai-agents: 1.2.0b5 azure-ai-documentintelligence: 1.0.2 azure-ai-projects: 2.0.0 azure-ai-textanalytics: 5.4.0 azure-ai-vision-imageanalysis: 1.0.0 azure-core: 1.38.2 azure-cosmos: 4.15.0 azure-identity: 1.25.2 azure-mgmt-logic: 10.0.0 azure-monitor-opentelemetry: 1.8.6 azure-search-documents: 11.6.0 httpx: 0.28.1 jsonpatch: 1.33 langgraph: 1.0.10 numpy: 2.2.6 openai: 2.26.0 opentelemetry-api: 1.39.0 opentelemetry-instrumentation: 0.60b0 opentelemetry-instrumentation-threading: 0.60b0 opentelemetry-sdk: 1.39.0 opentelemetry-semantic-conventions: 0.60b0 opentelemetry-semantic-conventions-ai: 0.4.15 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pytest: 7.4.4 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 six: 1.17.0 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 vcrpy: 8.1.1 wrapt: 1.17.3 xxhash: 3.6.0 zstandard: 0.25.0

PR fix notes

PR #35693: fix(openai): add type: message to Responses API input items

Description (problem / solution / changelog)

Problem

_construct_responses_api_input() constructs user/system/developer message dicts with only role and content but omits the required "type": "message" field. While OpenAI's endpoint infers the type silently, strict OpenAI-compatible endpoints like Azure AI Foundry reject the request with HTTP 400.

Assistant messages already include "type": "message" — this is an asymmetry bug.

Closes #35688

Fix

Add "type": "message" to all non-assistant message constructions in _construct_responses_api_input() (two lines: one for list content, one for string content).

Tests

  • Updated existing tests to assert type: "message" on user/system/developer items.
  • Added test__construct_responses_api_input_message_type_on_all_roles as a dedicated regression test for #35688.

Changed files

  • libs/langchain_v1/tests/cassettes/test_inference_to_native_output[True].yaml.gz (modified, +0/-0)
  • libs/langchain_v1/tests/cassettes/test_inference_to_tool_output[True].yaml.gz (modified, +0/-0)
  • libs/langchain_v1/tests/cassettes/test_strict_mode[True].yaml.gz (modified, +0/-0)
  • libs/langchain_v1/tests/unit_tests/conftest.py (modified, +20/-0)
  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +2/-0)
  • libs/partners/openai/tests/cassettes/TestOpenAIResponses.test_stream_time.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_agent_loop.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_agent_loop_streaming.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_client_executed_tool_search.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_code_interpreter.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_compaction.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_compaction_streaming.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_custom_tool.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_file_search.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_function_calling.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_image_generation_multi_turn.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_image_generation_streaming.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_incomplete_response.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_mcp_builtin.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_mcp_builtin_zdr.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_parsed_pydantic_schema.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_reasoning.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_schema_parsing_failures_responses_api.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_schema_parsing_failures_responses_api_async.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_stream_reasoning_summary.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_tool_search.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_tool_search_streaming.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/cassettes/test_web_search.yaml.gz (modified, +0/-0)
  • libs/partners/openai/tests/integration_tests/chat_models/test_base.py (modified, +6/-2)
  • libs/partners/openai/tests/integration_tests/chat_models/test_base_standard.py (modified, +3/-1)
  • libs/partners/openai/tests/integration_tests/chat_models/test_responses_standard.py (modified, +3/-1)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +39/-0)
  • libs/partners/openai/tests/unit_tests/test_tools.py (modified, +1/-1)

PR #35706: fix(openai): include message type in Responses API input items

Description (problem / solution / changelog)

Summary

  • add type: "message" for user/system/developer items emitted by _construct_responses_api_input
  • strengthen regression tests for human/system/developer message conversion paths

Testing

  • OPENAI_API_KEY=test COVERAGE_FILE=/tmp/langchain-35688-pass1.coverage uv run --python 3.12 pytest tests/unit_tests/chat_models/test_base.py -k 'construct_responses_api_input and (multiple_message_types or human_message_with_text_blocks_conversion or human_message_with_image_url_conversion)' -q\n- OPENAI_API_KEY=test COVERAGE_FILE=/tmp/langchain-35688-pass2.coverage uv run --python 3.12 pytest tests/unit_tests/chat_models/test_base.py -k 'construct_responses_api_input and (multiple_message_types or human_message_with_text_blocks_conversion or human_message_with_image_url_conversion)' -q\n\nFixes #35688

Changed files

  • libs/langchain_v1/tests/cassettes/test_inference_to_native_output[True].yaml.gz (modified, +0/-0)
  • libs/langchain_v1/tests/cassettes/test_inference_to_tool_output[True].yaml.gz (modified, +0/-0)
  • libs/langchain_v1/tests/cassettes/test_strict_mode[True].yaml.gz (modified, +0/-0)
  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +2/-0)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +8/-0)
  • libs/partners/openai/tests/unit_tests/test_tools.py (modified, +1/-1)

PR #35707: fix(langchain-openai): add missing type:"message" to user/system/developer items in Responses API input

Description (problem / solution / changelog)

Problem

_construct_responses_api_input() in langchain_openai/chat_models/base.py converts LangChain messages to the OpenAI Responses API format. For user, system, and developer roles it appends the dict produced by _convert_message_to_dict(), but that helper only sets "role" and "content" — it does not set "type".

The Responses API requires every input item to carry a top-level "type" field ("message", "function_call", "function_call_output", etc.). Omitting it causes a 400 error when targeting Azure AI Foundry or any strict Responses API implementation:

BadRequestError: Error code: 400 - {'error': {'message': "Invalid value: ''. Supported values are: 'apply_patch_call', ..., 'message', ..., and 'web_search_call'.", 'type': 'invalid_request_error', 'param': 'input[1]', 'code': 'invalid_value'}}

Minimal reproduction:

from langchain_openai import ChatOpenAI

model = ChatOpenAI(base_url="https://<resource>.services.ai.azure.com/openai/v1", ...)
model.invoke([
    {"role": "developer", "content": "Translate from English into Italian"},
    {"role": "user", "content": "hi!"},
])
# Before fix: BadRequestError 400 — missing "type" field
# After fix:  Works correctly

Fix

Call msg.setdefault("type", "message") before appending for the user/system/developer branch. Using setdefault preserves any "type" that may already be set while injecting the correct default ("message") for the common case.

Closes #35688

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +5/-0)

PR #35714: fix(openai): add missing type field to user/system/developer messages in responses api

Description (problem / solution / changelog)

Description

Fixes #35688

_construct_responses_api_input was missing the type: message field on user, system, and developer message items when constructing input for the OpenAI Responses API. Assistant messages already had this field set correctly (lines 4293, 4323), but the branch handling user/system/developer roles (lines 4353-4372) omitted it.

This causes 400 errors from Azure AI Foundry, which requires all input items to have a type field according to the Responses API spec.

Changes

  • Added msg["type"] = "message" before appending user/system/developer messages to the input list, for both string content and list content paths
  • Updated existing tests to verify the type field is present on these message types

Issue

https://github.com/langchain-ai/langchain/issues/35688

Changed files

  • libs/core/langchain_core/messages/utils.py (modified, +71/-7)
  • libs/core/tests/unit_tests/messages/test_utils.py (modified, +87/-0)
  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +2/-0)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +6/-0)

Code Example

from langchain_openai import ChatOpenAI  # or any subclass targeting Azure AI Foundry

model = ChatOpenAI(base_url="https://<resource>.services.ai.azure.com/openai/v1", ...)

model.invoke([
    {"role": "developer", "content": "Translate from English into Italian"},
    {"role": "user", "content": "hi!"},
])

---

BadRequestError: Error code: 400 - {'error': {'message': "Invalid value: ''. Supported values are: 
'apply_patch_call', ..., 'message', ..., and 'web_search_call'.",
'type': 'invalid_request_error', 'param': 'input[1]', 'code': 'invalid_value'}}
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from langchain_openai import ChatOpenAI  # or any subclass targeting Azure AI Foundry

model = ChatOpenAI(base_url="https://<resource>.services.ai.azure.com/openai/v1", ...)

model.invoke([
    {"role": "developer", "content": "Translate from English into Italian"},
    {"role": "user", "content": "hi!"},
])

Error Message and Stack Trace (if applicable)

BadRequestError: Error code: 400 - {'error': {'message': "Invalid value: ''. Supported values are: 
'apply_patch_call', ..., 'message', ..., and 'web_search_call'.",
'type': 'invalid_request_error', 'param': 'input[1]', 'code': 'invalid_value'}}

Description

_construct_responses_api_input() in langchain_openai/chat_models/base.py builds Responses API input items without explicitly setting "type": "message" on user, system, and developer message dicts. OpenAI's native endpoint silently infers the type, but other OpenAI-compatible endpoints (e.g. Microsoft Foundry) enforce the schema strictly and reject the request with a 400 Bad Request.

System Info

System Information

OS: Linux OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 Python Version: 3.12.3 (main, Jan 22 2026, 20:57:42) [GCC 13.3.0]

Package Information

langchain_core: 1.2.17 langchain: 1.2.10 langsmith: 0.7.13 langchain_azure_ai: 1.1.0 langchain_openai: 1.1.10 langgraph_sdk: 0.3.9

Optional packages not installed

deepagents deepagents-cli

Other Dependencies

aiohttp: 3.13.3 azure-ai-agents: 1.2.0b5 azure-ai-documentintelligence: 1.0.2 azure-ai-projects: 2.0.0 azure-ai-textanalytics: 5.4.0 azure-ai-vision-imageanalysis: 1.0.0 azure-core: 1.38.2 azure-cosmos: 4.15.0 azure-identity: 1.25.2 azure-mgmt-logic: 10.0.0 azure-monitor-opentelemetry: 1.8.6 azure-search-documents: 11.6.0 httpx: 0.28.1 jsonpatch: 1.33 langgraph: 1.0.10 numpy: 2.2.6 openai: 2.26.0 opentelemetry-api: 1.39.0 opentelemetry-instrumentation: 0.60b0 opentelemetry-instrumentation-threading: 0.60b0 opentelemetry-sdk: 1.39.0 opentelemetry-semantic-conventions: 0.60b0 opentelemetry-semantic-conventions-ai: 0.4.15 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pytest: 7.4.4 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 six: 1.17.0 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 vcrpy: 8.1.1 wrapt: 1.17.3 xxhash: 3.6.0 zstandard: 0.25.0

extent analysis

Fix Plan

Fix 1: Update _construct_responses_api_input() in langchain_openai/chat_models/base.py

  • Update Code:

def _construct_responses_api_input(self, messages): responses_api_input = [] for message in messages: message_dict = { "role": message["role"], "content": message["content"], "type": "message", # Add this line to set the type explicitly } responses_api_input.append(message_dict) return responses_api_input


#### Fix 2: Update `invoke()` method in langchain_openai/chat_models/base.py

*   **Update Code:**
    ```python
def invoke(self, messages):
    responses_api_input = self._construct_responses_api_input(messages)
    # ... rest of the method remains the same

Fix 3: Update invoke() method in langchain_openai/chat_models/base.py to handle different OpenAI-compatible endpoints

  • Update Code:

def invoke(self, messages): responses_api_input = self._construct_responses_api_input(messages) if self.base_url.endswith("azure.ai"): # Check if it's Azure AI Foundry responses_api_input = [{"type": "message", **message} for message in responses_api_input] # ... rest of the method remains the same


### Verification

1.  Update the `langchain_openai` package to the latest version.
2.  Run the reproduction steps again with the updated package.
3.  Verify that the `BadRequestError` is resolved and the request is successful.

### Extra Tips

*   Make sure to test the updated code with different OpenAI-compatible endpoints to ensure it works as expected.
*   Consider adding a check for the `base_url` to handle other OpenAI-compatible endpoints that may have different schema requirements.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix `_construct_responses_api_input` omits type: "message" on user/system/developer items, breaking Foundry Responses API Body: [4 pull requests, 5 comments, 6 participants]