Skip to content

Conversation

ronaldpereira
Copy link
Contributor

Fix: Structured Output empty content

When using structured output with newer Google Gemini (Beta) models with Generic Provider, it returns content as None, raising an Exception in langchain-core.

Example

Structured Response Schema

from pydantic import BaseModel, Field


class PlannerPlanOutput(BaseModel):
    """Structured plan describing intent before SQL generation."""

    intent: str = Field(description="Short phrase of the main analytical intent.")
    entities: list[str] = Field(
        default_factory=list, description="Relevant table/entity names from schema only."
    )
    metrics: list[str] = Field(
        default_factory=list,
        description="Requested metrics or aggregations (e.g. count distinct shoppers).",
    )
    time_filter: str | None = Field(description="Natural language time interval required or None.")

Response

{
  "annotations": null,
  "content": [
    {
      "text": null,
      "type": "TEXT"
    }
  ],
  "name": null,
  "refusal": null,
  "role": "ASSISTANT",
  "tool_calls": [
    {
      "arguments": "{\"time_filter\":null,\"metrics\":[\"count distinct shopper_id\"],\"intent\":\"Contar shoppers únicos\",\"entities\":[\"gold.shopper\"]}",
      "id": null,
      "name": "PlannerPlanOutput",
      "type": "FUNCTION"
    }
  ]
}

Error

ValidationError: 2 validation errors for AIMessage
content.str
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.11/v/string_type
content.list[union[str,dict[any,any]]]
  Input should be a valid list [type=list_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.11/v/list_type

Proposed Fix

As the Langchain BaseMessage content field only accepts Union[str, list[Union[str, dict]]], when the response content is None we can overwrite it to be an empty string to keep the tool for structured output working as expected.

Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Sep 18, 2025
Copy link

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Sep 25, 2025
@YouNeedCryDear YouNeedCryDear self-requested a review October 9, 2025 21:41
@YouNeedCryDear YouNeedCryDear merged commit 74e8754 into oracle:main Oct 9, 2025
1 check passed
@ronaldpereira ronaldpereira deleted the patch-1 branch October 9, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants