Skip to content

fix(workflow): restore structured output fallback and boolean types - #44962

Merged
zyssyz123 merged 3 commits into
mainfrom
fix/cus-1763-structured-output
Oct 28, 2026
Merged

zyssyz123 merged 3 commits into
mainfrom
fix/cus-1763-structured-output

Conversation

@zyssyz123

@zyssyz123 zyssyz123 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Workflow LLM nodes using schema-prompt fallback can fail at Graphon's capability check after the 1.18.0 upgrade. Boolean fields can also fail final schema validation because Dify converts native boolean schemas to strings and instructs prompt-based responses to use strings.

Expose the prepared adapter's effective structured-output capability without mutating provider metadata, and keep native/prompt routing based on the original provider schema. Preserve boolean types in native schemas and prompt instructions. Polling retains provider-declared capabilities, and strict result validation remains enabled. Include the compatibility tests in KnowledgeFS's selective coverage suite so its changed-glue gate exercises the same adapter paths.

Related to CUS-1763.

Validation

  • Local targeted suite: 154 passed across the node runtime, structured-output compatibility, and output-parser tests. Coverage includes native/prompt routing, blocking/streamed responses, nested/array/nullable booleans, metadata immutability, polling, and rejection of string booleans.
  • Targeted Ruff checks and formatting, source type checks, and strict type checks for the new compatibility test passed.
  • KnowledgeFS changed-glue gate: reproduced the original 7/9 (77.78%) result with its existing test selection, then verified 9/9 (100%) after including the compatibility tests; the 90% threshold is unchanged.
  • SaaS dev: deployed bcb2364d0dad7b2cce71963c45e042bba9dfe265 through the existing deploy/saas build/deploy workflows. API and workflow workers run the same new image.
  • Reproduced both failures before deployment in a dedicated synthetic application: gpt-6-sol failed boolean result validation, and gpt-4.1-nano failed the capability check.
  • After deployment, the real browser workflow using gpt-6-sol succeeded through Start, two LLM nodes, and End (run 71ebc9bd-7a2a-4764-b7af-7d5165b9bfa8, 4 steps, 250 tokens). Persisted node and workflow outputs preserved false in scalar/nested/array fields and true in the array.
  • Live prompt-fallback probe: used a real gpt-6-sol provider call through DifyPreparedLLM and Graphon's LLM node, with a process-local copy of provider metadata that omitted structured-output. The request included the schema and boolean instructions in the system prompt, omitted native json_schema, and succeeded with all four values retaining boolean types. Original provider metadata was unchanged. This is a controlled capability fixture with a real provider, not a naturally non-native model end-to-end test.
  • Environment limitation: the configured naturally non-native gpt-4.1-nano passed the capability gate after deployment, but its upstream API returned a model-deprecated 404; that request is not counted as successful fallback output validation.

Checklist

  • This change requires a documentation update, included: Dify Document (not applicable)
  • I understand that this PR may be closed in case there was no previous discussion or issues.
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly. (not applicable)
  • I ran make lint && make type-check (backend) and vp staged (frontend). (targeted checks above; no frontend changes)

From Codex

@github-actions github-actions Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 79.89% 79.89% +0.01%
Strict coverage 79.58% 79.58% +0.01%
Typed symbols 76,591 76,614 +23
Untyped symbols 19,358 19,356 -2
Modules 3978 3979 +1

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-10-28 10:30:05.237203594 +0000
+++ /tmp/pyrefly_pr.txt	2026-10-28 10:29:54.377055484 +0000
@@ -3947,23 +3947,19 @@
 ERROR Object of class `NoneType` has no attribute `split` [missing-attribute]
    --> tests/unit_tests/core/helper/test_trace_id_helper.py:361:21
 ERROR Class member `_ModelInstance.invoke_llm` overrides parent class `ModelInstance` in an inconsistent manner [bad-override]
-  --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:66:9
+  --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:68:9
 ERROR Class member `_ModelInstance.invoke_llm` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-  --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:66:9
+  --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:68:9
 ERROR Argument `None` is not assignable to parameter `schema` with type `dict[str, Any]` in function `core.llm_generator.output_parser.structured_output.remove_additional_properties` [bad-argument-type]
-  --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:86:38
+  --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:89:38
 ERROR Argument `list[@_]` is not assignable to parameter `schema` with type `dict[str, Any]` in function `core.llm_generator.output_parser.structured_output.remove_additional_properties` [bad-argument-type]
-  --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:87:38
-ERROR Argument `None` is not assignable to parameter `schema` with type `dict[str, Any]` in function `core.llm_generator.output_parser.structured_output.convert_boolean_to_string` [bad-argument-type]
-   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:104:35
-ERROR Argument `list[@_]` is not assignable to parameter `schema` with type `dict[str, Any]` in function `core.llm_generator.output_parser.structured_output.convert_boolean_to_string` [bad-argument-type]
-   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:105:35
+  --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:90:38
 ERROR `in` is not supported between `Literal['Existing system prompt']` and `None` [not-iterable]
-   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:285:16
+   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:390:16
 ERROR `in` is not supported between `str` and `None` [not-iterable]
-   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:286:16
+   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:391:16
 ERROR `in` is not supported between `str` and `None` [not-iterable]
-   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:297:16
+   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:402:16
 ERROR Argument `() -> Session` is not assignable to parameter `session_factory` with type `sessionmaker[@_]` in function `sqlalchemy.orm.scoping.scoped_session.__init__` [bad-argument-type]
    --> tests/unit_tests/core/llm_generator/test_llm_generator.py:159:35
 ERROR Keyword argument `access_token` with type `Literal['at']` is not assignable to parameter `**kwargs` with type `dict[str, str]` in function `typing.MutableMapping.update` [bad-argument-type]

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.53%. Comparing base (1f500e5) to head (f98ef31).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #44962   +/-   ##
=======================================
  Coverage   89.52%   89.53%           
=======================================
  Files        6009     6009           
  Lines      376843   376837    -6     
  Branches    76238    76232    -6     
=======================================
+ Hits       337380   337390   +10     
+ Misses      33465    33450   -15     
+ Partials     5998     5997    -1     
Flag Coverage Δ
api 89.39% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@laipz8200 laipz8200 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants