{"record":{"id":"06f14d00e36dbba7","repo":"langgenius/dify","slug":"invalid-filters-06f14d","errorCode":null,"errorMessage":"Invalid filters","messagePattern":"Invalid filters","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py","lineNumber":632,"sourceCode":"    )\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @edit_permission_required\n    @rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_EDIT)\n    @get_rag_pipeline\n    @model_validate(DefaultBlockConfigQuery)\n    def get(self, req_data: DefaultBlockConfigQuery, pipeline: Pipeline, block_type: str):\n        \"\"\"\n        Get default block config\n        \"\"\"\n\n        filters = None\n        if req_data.q:\n            try:\n                filters = json.loads(req_data.q)\n            except json.JSONDecodeError:\n                raise ValueError(\"Invalid filters\")\n\n        # Get default block configs\n        rag_pipeline_service = RagPipelineService(db.session())\n        return rag_pipeline_service.get_default_block_config(node_type=block_type, filters=filters)\n\n\n@console_ns.route(\"/rag/pipelines/<uuid:pipeline_id>/workflows\")\nclass PublishedAllRagPipelineApi(Resource):\n    @console_ns.doc(params=query_params_from_model(WorkflowListQuery))\n    @console_ns.response(\n        200,\n        \"Published workflows retrieved successfully\",\n        console_ns.models[WorkflowPaginationResponse.__name__],\n    )\n    @console_ns.response(403, \"Permission denied\")\n    @setup_required\n    @login_required\n    @account_initialization_required","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py#L614-L650","documentation":"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.","triggerScenarios":"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\").","commonSituations":"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.","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)."],"exampleFix":"// before\nfilters = json.loads(req_data.q)  // may throw JSONDecodeError -> ValueError(\"Invalid filters\")\n// after (client)\nconst url = `/default-config?q=${encodeURIComponent(JSON.stringify({ provider: 'openai' }))}`","handlingStrategy":"validation","validationCode":"function buildBlockConfigUrl(pipelineId, blockType, filters) {\n  let q = '';\n  if (filters) {\n    const s = JSON.stringify(filters);\n    JSON.parse(s); // throws locally if not serializable\n    q = `?q=${encodeURIComponent(s)}`;\n  }\n  return `/rag/pipelines/${pipelineId}/workflows/draft/blocks/${blockType}/default-config${q}`;\n}","typeGuard":"function isValidFilterObject(f) {\n  return f == null || (typeof f === 'object' && !Array.isArray(f) && Object.keys(f).length >= 0);\n}","tryCatchPattern":"try {\n  const r = await fetch(buildBlockConfigUrl(id, type, filters));\n  if (r.status === 500) { const e = await r.json(); if (e.message === 'Invalid filters') clearFilters(); else throw e; }\n} catch (e) { /* surface to user */ }","preventionTips":["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."],"tags":["rag-pipeline","workflow","validation","json","http-500"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}