adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Optional node field without a default fails the next node with "Field required"

Open TomShlaim opened this issue 3 weeks ago • 3 comments

🔴 Required Information

A workflow node returns a Pydantic model with an optional field set to None. ADK validates it, then serializes it with model_dump(exclude_none=True) (utils/_schema_utils.py:355, inside validate_node_data), which removes the key. The next node validates that dict against its input schema (workflow/_base_node.py:166); the key is missing, and a field without a default is required, so Pydantic raises Field required. A field typed X | None passes only when it also carries = None.

The JSON path dumps the same way (:260, :265). Same code in 2.11.0 (:299) through 2.14.0.

Steps to Reproduce:

  1. pip install google-adk==2.14.0
  2. Run the script below: a producer node returns Item(name="x", note=None), a consumer node reads it.
  3. Change note: str | None to note: str | None = None and run again.

Expected Behavior:

Step 2 prints output: name=x note=None. A None that passed the producer's output schema reaches the consumer as None.

Observed Behavior:

google-adk 2.14.0
Traceback (most recent call last):
  ...
  File ".../google/adk/workflow/_dynamic_node_scheduler.py", line 455, in _execute_step
    raise ValidationError.from_exception_data(
pydantic_core._pydantic_core.ValidationError: 1 validation error for dynamic node 'consume'
note
  Field required [type=missing, input_value={'name': 'x'}, input_type=dict]

Step 3 (with = None) prints output: {'name': 'x'} for the producer, the note key already gone, then output: name=x note=None.

Environment Details:

  • ADK Library Version (pip show google-adk): 2.14.0 (same code in 2.11.0, 2.12.0 and 2.13.0)
  • Desktop OS: macOS 15
  • Python Version (python -V): Python 3.12.8

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: N/A (function nodes only)

🟡 Optional Information

Regression: Yes. validate_node_data and its exclude_none=True dump arrived in 2.5.0; 2.4.0 has neither. We hit it when upgrading from 2.3.0 to 2.11.0.

Logs: See Observed Behavior.

Screenshots / Video: N/A

Additional Context: Workaround in use: every X | None field gets a = None default, enforced by a test that sweeps all node schemas. Suggested fix: serialize with exclude_unset=True, so a key set to None on purpose survives, or keep None for fields that have no default.

Minimal Reproduction Code:

import asyncio

import google.adk
from google.adk.runners import InMemoryRunner
from google.adk.workflow import START, Workflow, node
from google.genai import types
from pydantic import BaseModel


class Item(BaseModel):
    name: str
    note: str | None


@node
def produce(node_input) -> Item:
    return Item(name="x", note=None)


@node
def consume(node_input: Item) -> str:
    return f"name={node_input.name} note={node_input.note}"


async def main():
    print("google-adk", google.adk.__version__)
    runner = InMemoryRunner(node=Workflow(name="root", edges=[(START, produce, consume)]))
    session = await runner.session_service.create_session(app_name=runner.app_name, user_id="u")
    async for event in runner.run_async(user_id="u", session_id=session.id, new_message=types.UserContent("go")):
        if event.output is not None:
            print("output:", event.output)


asyncio.run(main())

How often has this issue occurred?: Always (100%)

TomShlaim avatar Nov 09 '26 10:11 TomShlaim

can i take this? plan is to stop validate_node_data dropping explicit None fields (exclude_unset instead of exclude_none in _to_serializable) so a validated None reaches the next node, plus a producer/consumer workflow test with a required str | None field.

its-amann avatar Nov 09 '26 11:11 its-amann

Thanks @TomShlaim, your script fails the same way on 2.14.1. The exclude_none dump in validate_node_data drops note, and it’s been there since 2.5.0.

One heads-up on exclude_unset: it would also drop defaulted fields that were never set (e.g. count: int = 0) from event.output and state. An alternative I tried keeps exclude_none but puts None back for required fields, recursing into nested models and lists, and it passed both cases. Could you try that approach against your node schemas?

@its-amann it might be worth comparing both before you open the PR. Whichever we go with should also cover the JSON parse helpers.

Please test it thoroughly (nested models, list[Model], LLM JSON output with null) before raising the PR. Until then the = None default you’re already using is the safest workaround.

surajksharma07 avatar Nov 13 '26 07:11 surajksharma07

@surajksharma07 Sounds reasonable :)

TomShlaim avatar Nov 15 '26 07:11 TomShlaim