From 4721c05a7b2f49b335caaedb6251b006229dd190 Mon Sep 17 00:00:00 2001 From: vchen7629 Date: Thu, 2 Jul 2026 12:20:05 -0700 Subject: [PATCH 1/7] fix: updated agent model dump to exclude delta field Signed-off-by: vchen7629 --- src/agent.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/agent.py b/src/agent.py index b146afae1..1eacd115f 100644 --- a/src/agent.py +++ b/src/agent.py @@ -175,8 +175,16 @@ async def async_response_stream( try: # Try to serialize the chunk object if hasattr(chunk, "model_dump"): - # Pydantic model - chunk_data = chunk.model_dump() + # Pydantic model. Exclude "delta" from serialization since Langflow's + # /response SSE wraps text deltas as {"content": "..."} for every provider but + # openai SDK's event models declare/expect delta to be str so model_dump() will + # emit noisy logs (PydanticSerializationUnexpectedValue) for every chunk. Basically + # just reattach the raw (unvalidated) value afterwards to preserve same shape. + # TODO: replace this with just chunk.model_dump() if langflow's /response SSE matches openai's + # SDK's delta: str schema + chunk_data = chunk.model_dump(exclude={"delta"}) + if hasattr(chunk, "delta"): + chunk_data["delta"] = chunk.delta elif hasattr(chunk, "__dict__"): chunk_data = chunk.__dict__ else: From 4d73a5f13a0d7a462b2adb9e8bebaa4b0aa9c751 Mon Sep 17 00:00:00 2001 From: vchen7629 Date: Thu, 2 Jul 2026 12:21:29 -0700 Subject: [PATCH 2/7] test: added regression unit test to verify response field + no warnings --- tests/unit/test_agent_stream_delta.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/unit/test_agent_stream_delta.py diff --git a/tests/unit/test_agent_stream_delta.py b/tests/unit/test_agent_stream_delta.py new file mode 100644 index 000000000..5aecaecfc --- /dev/null +++ b/tests/unit/test_agent_stream_delta.py @@ -0,0 +1,25 @@ +import warnings + +from pydantic import BaseModel + + +class FakeTextDeltaEvent(BaseModel): + """Mirrors openai's ResponseTextDeltaEvent: `delta` is declared as `str`.""" + + delta: str + type: str + + +def test_model_dump_excluding_delta_avoids_warning_and_preserves_dict_shape() -> None: + chunk = FakeTextDeltaEvent.model_construct( + delta={"content": "Hello"}, type="response.output_text.delta" + ) + + with warnings.catch_warnings(): + warnings.simplefilter("error") + + chunk_data = chunk.model_dump(exclude={"delta"}) + chunk_data["delta"] = chunk.delta + + assert chunk_data["delta"] == {"content": "Hello"} + assert chunk_data["type"] == "response.output_text.delta" \ No newline at end of file From 6d93ab088fac16b40488febbf21c618ef50c1518 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 19:23:57 +0000 Subject: [PATCH 3/7] style: ruff autofix (auto) --- src/agent.py | 2 +- tests/unit/test_agent_stream_delta.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent.py b/src/agent.py index 1eacd115f..c8daf41da 100644 --- a/src/agent.py +++ b/src/agent.py @@ -180,7 +180,7 @@ async def async_response_stream( # openai SDK's event models declare/expect delta to be str so model_dump() will # emit noisy logs (PydanticSerializationUnexpectedValue) for every chunk. Basically # just reattach the raw (unvalidated) value afterwards to preserve same shape. - # TODO: replace this with just chunk.model_dump() if langflow's /response SSE matches openai's + # TODO: replace this with just chunk.model_dump() if langflow's /response SSE matches openai's # SDK's delta: str schema chunk_data = chunk.model_dump(exclude={"delta"}) if hasattr(chunk, "delta"): diff --git a/tests/unit/test_agent_stream_delta.py b/tests/unit/test_agent_stream_delta.py index 5aecaecfc..700291d74 100644 --- a/tests/unit/test_agent_stream_delta.py +++ b/tests/unit/test_agent_stream_delta.py @@ -22,4 +22,4 @@ def test_model_dump_excluding_delta_avoids_warning_and_preserves_dict_shape() -> chunk_data["delta"] = chunk.delta assert chunk_data["delta"] == {"content": "Hello"} - assert chunk_data["type"] == "response.output_text.delta" \ No newline at end of file + assert chunk_data["type"] == "response.output_text.delta" From 1b0d5ebe81268e0db41f3aee1295b1a08a2c10d5 Mon Sep 17 00:00:00 2001 From: vchen7629 Date: Thu, 2 Jul 2026 13:49:49 -0700 Subject: [PATCH 4/7] test: added additional unit test to verify that model_dump without exclusion raises the warning Signed-off-by: vchen7629 --- tests/unit/test_agent_stream_delta.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_agent_stream_delta.py b/tests/unit/test_agent_stream_delta.py index 700291d74..3f2da6213 100644 --- a/tests/unit/test_agent_stream_delta.py +++ b/tests/unit/test_agent_stream_delta.py @@ -9,12 +9,20 @@ class FakeTextDeltaEvent(BaseModel): delta: str type: str +chunk = FakeTextDeltaEvent.model_construct( + delta={"content": "Hello"}, type="response.output_text.delta" +) -def test_model_dump_excluding_delta_avoids_warning_and_preserves_dict_shape() -> None: - chunk = FakeTextDeltaEvent.model_construct( - delta={"content": "Hello"}, type="response.output_text.delta" - ) +def test_model_dump_without_exclusion_raises_serialization_warning() -> None: + with warnings.catch_warnings(record=True) as recorded: + warnings.simplefilter("always") + chunk.model_dump() + + assert recorded, "expected a serialization warning when delta has a type mismatch" + + +def test_model_dump_excluding_delta_avoids_warning_and_preserves_dict_shape() -> None: with warnings.catch_warnings(): warnings.simplefilter("error") From f966225d75868a56e2b7717170c1c3554386d2f4 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 20:50:37 +0000 Subject: [PATCH 5/7] style: ruff autofix (auto) --- tests/unit/test_agent_stream_delta.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_agent_stream_delta.py b/tests/unit/test_agent_stream_delta.py index 3f2da6213..68ff188ec 100644 --- a/tests/unit/test_agent_stream_delta.py +++ b/tests/unit/test_agent_stream_delta.py @@ -9,6 +9,7 @@ class FakeTextDeltaEvent(BaseModel): delta: str type: str + chunk = FakeTextDeltaEvent.model_construct( delta={"content": "Hello"}, type="response.output_text.delta" ) From 8e00f925f8f133d31544a8ae8ea53fa6b1ebe8bb Mon Sep 17 00:00:00 2001 From: vchen7629 Date: Thu, 2 Jul 2026 14:34:46 -0700 Subject: [PATCH 6/7] test: tighten delta warning assertion to match specific Pydantic error Signed-off-by: vchen7629 --- tests/unit/test_agent_stream_delta.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_agent_stream_delta.py b/tests/unit/test_agent_stream_delta.py index 68ff188ec..9df68bd39 100644 --- a/tests/unit/test_agent_stream_delta.py +++ b/tests/unit/test_agent_stream_delta.py @@ -20,7 +20,10 @@ def test_model_dump_without_exclusion_raises_serialization_warning() -> None: warnings.simplefilter("always") chunk.model_dump() - assert recorded, "expected a serialization warning when delta has a type mismatch" + assert any( + issubclass(w.category, UserWarning) and "PydanticSerializationUnexpectedValue" in str(w.message) + for w in recorded + ), "expected a PydanticSerializationUnexpectedValue warning for the delta type mismatch" def test_model_dump_excluding_delta_avoids_warning_and_preserves_dict_shape() -> None: From b19f1ceba6376ee05b98e4313e63050a71dc26e3 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 21:36:06 +0000 Subject: [PATCH 7/7] style: ruff autofix (auto) --- tests/unit/test_agent_stream_delta.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_agent_stream_delta.py b/tests/unit/test_agent_stream_delta.py index 9df68bd39..c6f59681f 100644 --- a/tests/unit/test_agent_stream_delta.py +++ b/tests/unit/test_agent_stream_delta.py @@ -21,7 +21,8 @@ def test_model_dump_without_exclusion_raises_serialization_warning() -> None: chunk.model_dump() assert any( - issubclass(w.category, UserWarning) and "PydanticSerializationUnexpectedValue" in str(w.message) + issubclass(w.category, UserWarning) + and "PydanticSerializationUnexpectedValue" in str(w.message) for w in recorded ), "expected a PydanticSerializationUnexpectedValue warning for the delta type mismatch"