Skip to content

fix: coerce UUID session_id to string in ChatOutputResponse#11958

Merged
HzaRashid merged 6 commits into
mainfrom
fix/lfx-chatresp-uuid
Mar 4, 2026
Merged

fix: coerce UUID session_id to string in ChatOutputResponse#11958
HzaRashid merged 6 commits into
mainfrom
fix/lfx-chatresp-uuid

Conversation

@HzaRashid
Copy link
Copy Markdown
Collaborator

@HzaRashid HzaRashid commented Mar 1, 2026

Explicitly coerces session_id inChatOutputResponse schema to be a string if a UUID is provided to prevent UUID inputs (common for session ids) from causing validation errors. Added tests covering model-level coercion.

Reproduction (before fix):

  1. In an isolated lfx environment, run: lfx run agent.json "hi", where agent.json is the simple agent starter flow.
  2. Observe exact failure:
    {"success": false, "type": "error", "exception_type": "ValidationError", "exception_message": "1 validation error for ChatOutputResponse\nsession_id\n Input should be a valid string [type=string_type, input_value=UUID('...'), input_type=UUID]\n For further information visit https://errors.pydantic.dev/2.12/v/string_type"}

Result (after fix):

  • Re-running the same command no longer fails on ChatOutputResponse.session_id UUID validation.

This failure occurs in LFX because the graph's session id is not pre-populated as it is in Langflow. See Line 255 in src/lfx/src/lfx/base/agents/agent.py.

Summary by CodeRabbit

  • New Features

    • Session identifiers provided as UUIDs are now automatically converted to string format consistently across API responses and data schemas.
  • Tests

    • Added comprehensive test coverage for session identifier handling, including coercion validation and error handling for invalid session identifier types across multiple modules.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 1, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The changes introduce UUID-to-string coercion for session_id fields across the backend and lfx codebases. A shared utility function coerce_to_str_if_uuid is added to both schema validator modules, with corresponding field validators implemented in ChatOutputResponse and DataOutputResponse schemas to ensure session_id values are consistently converted from UUID to string representation before validation.

Changes

Cohort / File(s) Summary
Utility Functions
src/backend/base/langflow/schema/validators.py, src/lfx/src/lfx/schema/validators.py
Added coerce_to_str_if_uuid helper function that converts UUID instances to strings, leaving other values unchanged.
Backend Schema Validators
src/backend/base/langflow/utils/schemas.py
Added field validator coerce_session_id_uuid_to_str and docstring to ChatOutputResponse to coerce UUID session_id values to strings before model validation.
LFX Schema Validators
src/lfx/src/lfx/utils/schemas.py
Added field validator coerce_session_id_uuid_to_str and docstring to both ChatOutputResponse and DataOutputResponse to coerce UUID session_id values to strings, with corresponding imports.
LFX Graph Vertex Integration
src/lfx/src/lfx/graph/vertex/base.py, src/lfx/src/lfx/graph/vertex/vertex_types.py
Integrated UUID-to-string coercion in extract_messages_from_artifacts using coerce_to_str_if_uuid before constructing ChatOutputResponse instances.
Backend Test Coverage
src/backend/tests/unit/utils/test_schemas.py
Added test cases validating UUID session_id coercion to string and rejection of non-string, non-UUID session_id values.
LFX Test Coverage
src/lfx/tests/unit/utils/test_schemas.py, src/lfx/tests/unit/graph/vertex/test_vertex_base.py
Added comprehensive tests for UUID session_id coercion, including test doubles with strict validation and monkeypatched schema replacements to verify stringified session_id in message construction.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 6 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Excessive Mock Usage Warning ⚠️ Warning Test file test_vertex_base.py exhibits excessive mocking: introduces _StrictChatOutputResponse test double, uses monkeypatch to replace schema classes across modules, and dedicates 80+ lines primarily to mock setup rather than testing core UUID coercion logic. Refactor tests to use real ChatOutputResponse objects with actual UUID inputs instead of test doubles. Extract pure UUID coercion function for focused unit testing, or use integration tests. This reduces mock-heavy setup and validates actual behavior.
✅ Passed checks (6 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 80.95% which is sufficient. The required threshold is 80.00%.
Test Coverage For New Implementations ✅ Passed PR includes comprehensive test coverage for UUID-to-string coercion implementations across backend and LFX with positive and negative test cases.
Test Quality And Coverage ✅ Passed Test coverage for UUID session_id coercion functionality is comprehensive, spanning three test files with proper pytest patterns, error handling validation, and monkeypatching for dependency injection.
Test File Naming And Structure ✅ Passed Test files follow proper pytest conventions with descriptive names and comprehensive coverage including both positive and negative scenarios across backend, LFX schemas, and LFX vertex modules.
Title check ✅ Passed The title 'fix: coerce UUID session_id to string in ChatOutputResponse' directly addresses the main change: adding UUID-to-string coercion for session_id in ChatOutputResponse and related schemas to fix Pydantic validation failures.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/lfx-chatresp-uuid

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the bug Something isn't working label Mar 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 23%
22.87% (7981/34889) 15.45% (4224/27334) 15.6% (1147/7348)

Unit Test Results

Tests Skipped Failures Errors Time
2611 0 💤 0 ❌ 0 🔥 43.757s ⏱️

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.36%. Comparing base (2fc6ca8) to head (6f01c7a).
⚠️ Report is 1 commits behind head on main.

❌ Your project status has failed because the head coverage (42.37%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11958      +/-   ##
==========================================
+ Coverage   37.31%   37.36%   +0.04%     
==========================================
  Files        1592     1592              
  Lines       78280    78304      +24     
  Branches    11824    11826       +2     
==========================================
+ Hits        29212    29256      +44     
+ Misses      47448    47426      -22     
- Partials     1620     1622       +2     
Flag Coverage Δ
backend 57.39% <100.00%> (+0.06%) ⬆️
frontend 20.49% <ø> (ø)
lfx 42.37% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/backend/base/langflow/utils/schemas.py 100.00% <100.00%> (ø)
src/lfx/src/lfx/utils/schemas.py 63.52% <100.00%> (+5.99%) ⬆️

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 1, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the helper expects str | UUID | None, but the call site's value for session is not necessarily of those types

🧹 Nitpick comments (1)
src/lfx/src/lfx/graph/vertex/vertex_types.py (1)

170-173: The isinstance check is redundant.

The coerce_to_str_if_uuid function already handles all input types safely (UUID → string, str → passthrough, None → passthrough, other → passthrough). The conditional adds complexity without changing behavior.

Consider simplifying to match base.py (line 449):

♻️ Simplify by removing redundant type check
-            raw_session_id = message_dict.get("session_id")
-            session_id = (
-                coerce_to_str_if_uuid(raw_session_id) if isinstance(raw_session_id, (UUID, str)) else raw_session_id
-            )
+            session_id = coerce_to_str_if_uuid(message_dict.get("session_id"))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lfx/src/lfx/graph/vertex/vertex_types.py` around lines 170 - 173, The
isinstance guard around coerce_to_str_if_uuid is redundant; change the
session_id assignment to call coerce_to_str_if_uuid(raw_session_id)
unconditionally (replace the conditional expression that references
raw_session_id, session_id and coerce_to_str_if_uuid with a direct call) so
behavior matches base.py usage and simplifies the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/lfx/src/lfx/graph/vertex/vertex_types.py`:
- Around line 170-173: The isinstance guard around coerce_to_str_if_uuid is
redundant; change the session_id assignment to call
coerce_to_str_if_uuid(raw_session_id) unconditionally (replace the conditional
expression that references raw_session_id, session_id and coerce_to_str_if_uuid
with a direct call) so behavior matches base.py usage and simplifies the code.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d602738 and 6ffe0d5.

📒 Files selected for processing (9)
  • src/backend/base/langflow/schema/validators.py
  • src/backend/base/langflow/utils/schemas.py
  • src/backend/tests/unit/utils/test_schemas.py
  • src/lfx/src/lfx/graph/vertex/base.py
  • src/lfx/src/lfx/graph/vertex/vertex_types.py
  • src/lfx/src/lfx/schema/validators.py
  • src/lfx/src/lfx/utils/schemas.py
  • src/lfx/tests/unit/graph/vertex/test_vertex_base.py
  • src/lfx/tests/unit/utils/test_schemas.py

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 1, 2026
@langflow-ai langflow-ai deleted a comment from coderabbitai Bot Mar 1, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 2, 2026
Comment thread src/lfx/src/lfx/graph/vertex/vertex_types.py Outdated
Comment thread src/lfx/src/lfx/graph/vertex/base.py Outdated
Comment thread src/backend/base/langflow/schema/validators.py Outdated
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 2, 2026
@HzaRashid HzaRashid requested a review from jordanrfrazier March 2, 2026 23:31
@HzaRashid HzaRashid changed the title fix: coerce UUID session_id to string in ChatOutputResponse and callers fix: coerce UUID session_id to string in ChatOutputResponse Mar 2, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 2, 2026
@HzaRashid
Copy link
Copy Markdown
Collaborator Author

Went for a middle ground approach, by validating session id to be str | uuid | None inside the ‘before’ validator with a more descriptive error message instead of silently coercing to str and then waiting for the ‘after’ check to fail with a generic message

@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Mar 3, 2026
@HzaRashid HzaRashid enabled auto-merge March 3, 2026 15:00
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 3, 2026
@HzaRashid HzaRashid added this pull request to the merge queue Mar 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 3, 2026
@HzaRashid HzaRashid added this pull request to the merge queue Mar 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 3, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 3, 2026
@HzaRashid HzaRashid added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit 5b16027 Mar 4, 2026
97 of 98 checks passed
@HzaRashid HzaRashid deleted the fix/lfx-chatresp-uuid branch March 4, 2026 03:42
HimavarshaVS pushed a commit that referenced this pull request Mar 10, 2026
* fix: coerce UUID session_id to string in ChatOutputResponse and lfx callsite

* simplify patching in tests

* validate and raise early

* valueerror instead of typerror
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants