langgenius/dify · error · ValueError
Invalid filters
Error message
Invalid filters
What it means
Bare ValueError('Invalid filters') raised inside DefaultBlockConfigApi.get (GET /apps/{app_id}/workflows/default-workflow-block-configs/{block_type}) when the 'q' query string is present but fails json.loads (json.JSONDecodeError). The value is forwarded as filters to WorkflowService.get_default_block_config. The ValueError propagates as HTTP 400 'Invalid filters'.
Source
Thrown at api/controllers/console/app/workflow.py:1390
@console_ns.doc(params=query_params_from_model(DefaultBlockConfigQuery))
@setup_required
@login_required
@account_initialization_required
@edit_permission_required
@rbac_permission_required(RBACResourceScope.APP, RBACPermission.APP_VIEW_LAYOUT)
@get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
def get(self, app_model: App, block_type: str):
"""
Get default block config
"""
args = DefaultBlockConfigQuery.model_validate(request.args.to_dict(flat=True))
filters = None
if args.q:
try:
filters = json.loads(args.q)
except json.JSONDecodeError:
raise ValueError("Invalid filters")
# Get default block configs
workflow_service = WorkflowService()
return workflow_service.get_default_block_config(node_type=block_type, filters=filters)
@console_ns.route("/apps/<uuid:app_id>/convert-to-workflow")
class ConvertToWorkflowApi(Resource):
@console_ns.expect(console_ns.models[ConvertToWorkflowPayload.__name__])
@console_ns.doc("convert_to_workflow")
@console_ns.doc(description="Convert application to workflow mode")
@console_ns.doc(params={"app_id": "Application ID"})
@console_ns.response(
200,
"Application converted to workflow successfully",
console_ns.models[NewAppResponse.__name__],
)
@console_ns.response(400, "Application cannot be converted")View on GitHub (pinned to ef8544b173)
Solutions
- URL-encode a JSON.stringify-ed object for the q parameter, or omit it entirely.
- Validate that q parses as JSON on the client before sending.
- If no filter is needed, drop the q query parameter.
Example fix
// before: raw, un-encoded JSON in the URL
fetch(`/apps/${appId}/workflows/default-workflow-block-configs/llm?q={provider:openai}`)
// after: JSON.stringify + encodeURIComponent
const q = encodeURIComponent(JSON.stringify({provider:'openai'}));
fetch(`/apps/${appId}/workflows/default-workflow-block-configs/llm?q=${q}`) Defensive patterns
Strategy: validation
Validate before calling
// Validate q parses as JSON before sending; drop it if it doesn't.
let q;
try { q = rawQ ? JSON.parse(rawQ) : undefined; } catch { q = undefined; /* or show client error */ }
const url = `/console/apps/${appId}/workflows/default-workflow-block-configs/${blockType}` +
(q ? `?q=${encodeURIComponent(JSON.stringify(q))}` : ''); Type guard
const isJsonString = (s): boolean => { try { JSON.parse(s); return true; } catch { return false; } }; Try / catch
try {
return await getDefaultBlockConfig(appId, blockType, q);
} catch (e) {
if (e?.status === 400 && /Invalid filters/i.test(e?.message)) {
// drop q and retry without filters
return getDefaultBlockConfig(appId, blockType, undefined);
}
throw e;
} Prevention
- Always build the q parameter with JSON.stringify + encodeURIComponent.
- Omit q entirely when no filter is needed.
- Add a client-side JSON validity check before issuing the request.
When it happens
Trigger: Passing a malformed 'q' parameter that is not valid JSON, e.g. ?q=foo or ?q={bad, on the default-block-config endpoint.
Common situations: Frontend builds the q param by string concatenation instead of JSON.stringify; copy-pasted URL with truncated JSON; manual API testing with unencoded braces.
Related errors
- missing inputs
- Workflow not initialized
- source workflow must be published
- usage_missing_arg
- no_file_uploaded
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/c2b59843d093df90.
Report an issue: GitHub.