Structured output rejects valid $defs names with JSON Pointer escapes
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
main (commit f318dd01)
Cloud or Self Hosted
Self Hosted (Source)
Steps to reproduce
- Configure a Dify Agent structured-output schema with a root $defs entry named
Widget/Infoand reference it from a property using the JSON Pointer tokenWidget~1Info:
{
"type": "object",
"properties": {"widget": {"$ref": "#/$defs/Widget~1Info"}},
"required": ["widget"],
"$defs": {
"Widget/Info": {
"type": "object",
"properties": {"id": {"type": "string"}},
"required": ["id"]
}
}
}
- Build the structured-output contract or start an Agent run with this schema.
✔️ Expected Behavior
The local reference resolves to the root $defs entry and Dify builds the structured-output contract with the referenced object schema.
❌ Actual Behavior
Contract construction raises ValueError: Local $ref '#/$defs/Widget~1Info' could not be resolved from $defs. The same failure occurs for names containing ~ and for percent-encoded fragment characters.
This reproduces in the current Dify Agent structured-output resolver; it is separate from #27577's older MCP tool-parameter parsing report.
The failure points to _inline_local_defs_refs() in dify-agent/src/dify_agent/layers/output/output_layer.py: it strips #/$defs/ and uses the remaining text directly as a $defs key. Thus Widget~1Info is looked up literally instead of resolving to Widget/Info; there is no percent-decoding or JSON Pointer unescaping on that path. [1]
For a fix, the resolver needs to interpret the fragment as a JSON Pointer rather than a raw definition name. Regression coverage should include /, ~, percent-encoded characters, and a literal ~1 in a definition name to catch accidental double-unescaping. The existing local-reference contract test already checks both the exposed schema and output validation, so it provides a model-independent place to add these cases. [2]
As a temporary schema-level workaround for this example, rename the definition to WidgetInfo and update the reference to #/$defs/WidgetInfo, avoiding the decoding path. This follows the literal-key lookup currently implemented. I haven’t executed the reproducer here. [3]
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.