langgenius/dify · error · ValueError
Invalid filters
Error message
Invalid filters
What it means
Raised as a raw ValueError inside GetDefaultBlockConfigApi.get when the optional `q` query parameter is present but fails to parse as JSON (json.JSONDecodeError). The endpoint is GET /rag/pipelines/<pipeline_id>/workflows/draft/blocks/<block_type>/default-config. Like other raw ValueErrors here, it surfaces as HTTP 500 rather than a 400, which is misleading for a client input error.
Source
Thrown at api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py:632
)
@setup_required
@login_required
@account_initialization_required
@edit_permission_required
@rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_EDIT)
@get_rag_pipeline
@model_validate(DefaultBlockConfigQuery)
def get(self, req_data: DefaultBlockConfigQuery, pipeline: Pipeline, block_type: str):
"""
Get default block config
"""
filters = None
if req_data.q:
try:
filters = json.loads(req_data.q)
except json.JSONDecodeError:
raise ValueError("Invalid filters")
# Get default block configs
rag_pipeline_service = RagPipelineService(db.session())
return rag_pipeline_service.get_default_block_config(node_type=block_type, filters=filters)
@console_ns.route("/rag/pipelines/<uuid:pipeline_id>/workflows")
class PublishedAllRagPipelineApi(Resource):
@console_ns.doc(params=query_params_from_model(WorkflowListQuery))
@console_ns.response(
200,
"Published workflows retrieved successfully",
console_ns.models[WorkflowPaginationResponse.__name__],
)
@console_ns.response(403, "Permission denied")
@setup_required
@login_required
@account_initialization_requiredView on GitHub (pinned to ef8544b173)
Solutions
- Send `q` as a URL-encoded JSON object, e.g. ?q=%7B%22provider%22%3A%22openai%22%7D.
- If you maintain the controller, replace `raise ValueError("Invalid filters")` with `raise BadRequest("Invalid filters")` to return a proper 400.
- Validate/JSON.stringify the filters on the client before adding them to the query string.
- Omit `q` entirely when no filter is needed (filters stays None).
Example fix
// before
filters = json.loads(req_data.q) // may throw JSONDecodeError -> ValueError("Invalid filters")
// after (client)
const url = `/default-config?q=${encodeURIComponent(JSON.stringify({ provider: 'openai' }))}` Defensive patterns
Strategy: validation
Validate before calling
function buildBlockConfigUrl(pipelineId, blockType, filters) {
let q = '';
if (filters) {
const s = JSON.stringify(filters);
JSON.parse(s); // throws locally if not serializable
q = `?q=${encodeURIComponent(s)}`;
}
return `/rag/pipelines/${pipelineId}/workflows/draft/blocks/${blockType}/default-config${q}`;
} Type guard
function isValidFilterObject(f) {
return f == null || (typeof f === 'object' && !Array.isArray(f) && Object.keys(f).length >= 0);
} Try / catch
try {
const r = await fetch(buildBlockConfigUrl(id, type, filters));
if (r.status === 500) { const e = await r.json(); if (e.message === 'Invalid filters') clearFilters(); else throw e; }
} catch (e) { /* surface to user */ } Prevention
- Always JSON.stringify then encodeURIComponent the filters.
- Omit q when no filter is needed.
- Add a unit test that round-trips the query through JSON.parse.
When it happens
Trigger: Sending ?q= with non-JSON content such as a raw string (?q=question), truncated JSON, or single-quoted text. The controller only enters the try branch when req_data.q is truthy, then json.loads throws and the except raises ValueError("Invalid filters").
Common situations: Frontend building the query string incorrectly (forgetting JSON.stringify); a user pasting a filter string; URL-encoding mistakes that corrupt the JSON; sending a Python-dict-style string instead of JSON.
Related errors
- usage_missing_arg
- Workflow node execution not found
- source workflow must be published
- usage_invalid_flag
- usage_missing_arg
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/06f14d00e36dbba7.
Report an issue: GitHub.