Skip to main content

Overview

A tool returns its results as messages and variables. This page covers the message interfaces, variable creation, and output schema definitions.

Message Types

Return different types of messages such as text, links, images, and JSON

Variables

Create and manipulate variables for workflow integration

Output Schema

Define custom output variables for workflow references

Data Structure

Message Return

Dify supports several message types—text, links, images, file blobs, and JSON—each returned through a dedicated interface. By default, a tool’s output in a workflow includes three fixed variables: files, text, and json. The methods below populate these variables.
While you can use methods like create_image_message to return an image, tools also support custom output variables, which make it easier to reference specific data in a workflow.

Message Types

string
required
URL to an image that will be downloaded and displayed.
URL to display as a clickable link.
string
required
Text content to display.
bytes
required
Raw file data in bytes.
dict
File metadata, including:
  • mime_type: The MIME type of the file, for example image/png.
  • Other metadata relevant to the file.
dict
required
Python dictionary to serialize as JSON.
When working with file blobs, always specify the mime_type in the meta dictionary to ensure proper handling of the file. For example: {"mime_type": "image/png"}.

Variables

string
required
Name of the variable to create or update.
Any/string
required
Value to assign to the variable:
  • Standard variables: any Python data type.
  • Streaming variables: string data only.
create_stream_variable_message currently only supports string data. Complex data types cannot be streamed with the typewriter effect.

Custom Output Variables

To reference a tool’s output variables in a Workflow application, declare which variables the tool might output using JSON Schema in the tool’s manifest.

Define Output Schema

object
required
Root object defining the tool’s output schema.
string
required
Must be object for tool output schemas.
object
required
Dictionary of all possible output variables.
object
Definition of each output variable, including its type and description.
Defining an output schema is not enough on its own: your implementation must still return each variable with create_variable_message(). Otherwise, the workflow receives None for that variable.

Example Implementation

For complex workflows, you can define multiple output variables and return them all. This gives workflow designers more flexibility when using your tool.

Examples

Complete Tool Implementation

When designing tools, consider both the direct output (what the user sees) and the variable output (what other workflow nodes can use). This separation provides flexibility in how your tool is used.
Last modified on July 9, 2026