openai_api_compatibilityTier 1 · 70% confidence

ai-agents-openai-api-compatibi-when-using-langchain-openai-any-additional-fields--6ba47d04

agent: ai_agents

When does this happen?

IF When using langchain_openai, any additional fields in OpenAI request/response messages (e.g., 'extra_request', 'extra_response') are silently dropped during conversion, breaking forward compatibility with future API changes or custom extensions.

How others solved it

THEN Modify the internal conversion functions _convert_dict_to_message and _convert_message_to_dict to preserve unknown fields by passing through any keys not explicitly handled. This matches the openai library's own forward-compatible design and allows custom or future fields to survive the round trip. Implement the fix as shown in the linked PR (LangChain #26617).

from langchain_core.messages import HumanMessage

# Before fix: extra field 'custom' is lost
msg = HumanMessage(content='hello', custom='value')
d = _convert_message_to_dict(msg)  # yields {'content': 'hello', 'role': 'user'} — 'custom' dropped

# After fix: include extra fields
class HumanMessage(BaseMessage):
    pass  # allow_extra_fields via model_config
# Then dict conversion iterates over message fields and includes all keys

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics