Repository navigation
Closed
Labels
Description
Summary
VariableEntity.json_schema is typed as dict[str, Any] | None with a default mode="after" validator. When VariableEntity.model_validate(...) is called with json_schema as a JSON string or an empty string, Pydantic raises a dict_type ValidationError before the validator ever runs.
This breaks every Dify workflow whose Start node has a JSON-typed variable with a schema, because Dify's frontend code editor persists the schema as raw text into the workflow definition, not as a parsed object.
Related issue in dify: langgenius/dify#31621
Reproduction
-
- insert a variable with json schema:
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"minimum": 0
}
},
"required": [
"name"
]
}-
- run the work flow
-
- error in worker process:
2026-05-29 05:49:29,565 ERROR [trace.py:309] 8c4280d69b Task tasks.app_generate.workflow_execute_task.workflow_based_app_execution_task[8f4fcdab-389d-4e4e-9262-131b4fce577e] raised unexpected: 1 validation error for VariableEntity
json_schema
Input should be a valid dictionary [type=dict_type, input_value='{\n "type": "object",\n...: [\n "name"\n ]\n}', input_type=str]
For further information visit https://errors.pydantic.dev/2.13/v/dict_type
Traceback (most recent call last):
File "/Users/shiyuanfang/Documents/dify_DMS/api/.venv/lib/python3.12/site-packages/celery/app/trace.py", line 585, in trace_task
R = retval = fun(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/Users/shiyuanfang/Documents/dify_DMS/api/extensions/ext_celery.py", line 101, in __call__
return self.run(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shiyuanfang/Documents/dify_DMS/api/tasks/app_generate/workflow_execute_task.py", line 269, in workflow_based_app_execution_task
return runner.run()
^^^^^^^^^^^^
File "/Users/shiyuanfang/Documents/dify_DMS/api/tasks/app_generate/workflow_execute_task.py", line 165, in run
response = self._run_app(
^^^^^^^^^^^^^^
File "/Users/shiyuanfang/Documents/dify_DMS/api/tasks/app_generate/workflow_execute_task.py", line 198, in _run_app
return WorkflowAppGenerator().generate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shiyuanfang/Documents/dify_DMS/api/core/app/apps/workflow/app_generator.py", line 154, in generate
app_config = WorkflowAppConfigManager.get_app_config(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shiyuanfang/Documents/dify_DMS/api/core/app/apps/workflow/app_config_manager.py", line 31, in get_app_config
variables=WorkflowVariablesConfigManager.convert(workflow=workflow),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shiyuanfang/Documents/dify_DMS/api/core/app/app_config/workflow_ui_based_app/variables/manager.py", line 23, in convert
variables.append(VariableEntity.model_validate(variable))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/shiyuanfang/Documents/dify_DMS/api/.venv/lib/python3.12/site-packages/pydantic/main.py", line 732, in model_validate
return cls.__pydantic_validator__.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for VariableEntity
json_schema
Input should be a valid dictionary [type=dict_type, input_value='{\n "type": "object",\n...: [\n "name"\n ]\n}', input_type=str]
For further information visit https://errors.pydantic.dev/2.13/v/dict_type
Environment
- dify 1.14.1
- graphon: 0.3.1
- Python: 3.12
- Pydantic: 2.13
Activity
dosubot commentedon May 29, 2026
Hi @shiyuanfang2nd! I'm Dosu and I’m helping the graphon team.
This is a confirmed bug that has been reported by multiple users across Dify versions 1.11.4 through 1.14.2 [1] [2].
The root cause is clear: the
json_schemafield onVariableEntityis typed asdict[str, Any] | None, and thevalidate_json_schemavalidator uses defaultmode="after"— meaning Pydantic's type coercion rejects the string before the validator ever runs [3]. Dify's frontend persists the schema as a raw JSON string in the workflow definition, so any workflow with a JSON-typed variable that has a schema hits this wall.The fix would be to add a
mode="before"validator that:Nonedictviajson.loads()dictandNonevalues unchangedSomething like:
The existing
validate_json_schema(mode="after") would then continue to validate the parsed dict against Draft 7 as before.To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
WH-2099 commentedon May 30, 2026
Thank you very much for your contribution. I have confirmed the issue and will follow up on it immediately.
fix(variables): accept JSON string and empty input for json_schema