Skip to content

langchain-openai: Responses API drops Azure content_filters from response_metadata #40983

Description

Checked other resources

  • I searched existing issues and found nothing on Azure content_filters with the Responses API.
  • The behavior is on master (884d2d6) and in langchain-openai 1.6.7.

Package

langchain-openai

Description

Azure OpenAI adds a top-level content_filters array to every Responses API result (non-streaming, and on the response.completed event when streaming). Microsoft documents it as an Azure extension to read from response.model_extra:
https://learn.microsoft.com/azure/foundry/openai/how-to/responses

The array is also the only signal that the content filters did not run. In that case the request "still completes without content filtering", and the result carries an error object inside content_filter_results (Scenario 6 in https://learn.microsoft.com/azure/ai-foundry/openai/concepts/content-filter; schema in azure-rest-api-specs, specification/ai-foundry/data-plane/Foundry/src/openai/responses/models.tsp).

_construct_lc_result_from_responses_api builds response_metadata from a fixed key list, so content_filters is dropped on both invoke and stream. With ChatOpenAI(base_url="https://<resource>.openai.azure.com/openai/v1/", use_responses_api=True) an application cannot follow Microsoft's "verify content filter execution" guidance. AzureChatOpenAI already surfaces content_filter_results for Chat Completions; the Responses path has no equivalent.

Proposed fix

Add "content_filters" to the key list in _construct_lc_result_from_responses_api. Both paths go through that function, so it is a one-line change plus a unit test for each path. I have it ready and would like to be assigned.

Reproduction

from openai.types.responses import Response
from langchain_openai.chat_models.base import _construct_lc_result_from_responses_api

response = Response.model_validate({
    "id": "resp_1", "created_at": 0, "model": "gpt-5.4-mini", "object": "response",
    "parallel_tool_calls": True, "tools": [], "tool_choice": "auto", "output": [],
    "content_filters": [{"source_type": "prompt", "blocked": False,
                         "content_filter_results": {"error": {"code": 1, "message": "The contents are not filtered"}}}],
})
metadata = _construct_lc_result_from_responses_api(response).generations[0].message.response_metadata
assert "content_filters" in metadata  # fails today

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    externalopenai`langchain-openai` package issues & PRs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions