Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

support returning structured output when using LLM API non streaming invocation (#26451)

goofy86c3c58e64b2
diff --git a/api/core/workflow/node_events/node.py b/api/core/workflow/node_events/node.py
index c1aeb9fe27e..93dfefb6798 100644
--- a/api/core/workflow/node_events/node.py
+++ b/api/core/workflow/node_events/node.py
@@ -20,6 +20,7 @@ class ModelInvokeCompletedEvent(NodeEventBase):
usage: LLMUsage
finish_reason: str | None = None
reasoning_content: str | None = None
+ structured_output: dict | None = None
class RunRetryEvent(NodeEventBase):
diff --git a/api/core/workflow/nodes/llm/node.py b/api/core/workflow/nodes/llm/node.py
index 7767440be60..36183bf8db9 100644
--- a/api/core/workflow/nodes/llm/node.py
+++ b/api/core/workflow/nodes/llm/node.py
@@ -23,6 +23,7 @@ from core.model_runtime.entities.llm_entities import (
LLMResult,
LLMResultChunk,
LLMResultChunkWithStructuredOutput,
+ LLMResultWithStructuredOutput,
LLMStructuredOutput,
LLMUsage,
)
@@ -278,6 +279,13 @@ class LLMNode(Node):
# Extract clean text from <think> tags
clean_text, _ = LLMNode._split_reasoning(result_text, self._node_data.reasoning_format)
+ # Process structured output if available from the event.
+ structured_output = (
+ LLMStructuredOutput(structured_output=event.structured_output)
+ if event.structured_output
+ else None
+ )
+
# deduct quota
llm_utils.deduct_llm_quota(tenant_id=self.tenant_id, model_instance=model_instance, usage=usage)
break
@@ -1048,7 +1056,7 @@ class LLMNode(Node):
@staticmethod
def handle_blocking_result(
*,
- invoke_result: LLMResult,
+ invoke_result: LLMResult | LLMResultWithStructuredOutput,
saver: LLMFileSaver,
file_outputs: list["File"],
reasoning_format: Literal["separated", "tagged"] = "tagged",
@@ -1079,6 +1087,8 @@ class LLMNode(Node):
finish_reason=None,
# Reasoning content for workflow variables and downstream nodes
reasoning_content=reasoning_content,
+ # Pass structured output if enabled
+ structured_output=getattr(invoke_result, "structured_output", None),
)
@staticmethod