{"record":{"id":"57472ab8de8de6d3","repo":"iflytek/astron-agent","slug":"group-is-required-when-ragtype-is-not-ragflow-rag","errorCode":null,"errorMessage":"group is required when ragType is not Ragflow-RAG","messagePattern":"group is required when ragType is not Ragflow-RAG","errorType":"validation","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"core/knowledge/domain/entity/chunk_dto.py","lineNumber":40,"sourceCode":"\n_DATASET_ID_LIST_DESC = (\n    \"RAGFlow dataset.id values for Ragflow-RAG routing; \"\n    \"None or empty uses the default dataset.\"\n)\n\n\nclass RAGType(str, Enum):\n    \"\"\"Define RAG type enumeration\"\"\"\n\n    AIUI_RAG2 = \"AIUI-RAG2\"\n    CBG_RAG = \"CBG-RAG\"\n    SparkDesk_RAG = \"SparkDesk-RAG\"\n    RagFlow_RAG = \"Ragflow-RAG\"\n\n\ndef _require_group_for_non_ragflow(rag_type: RAGType, group: Optional[str]) -> None:\n    if rag_type != RAGType.RagFlow_RAG and not group:\n        raise ValueError(\"group is required when ragType is not Ragflow-RAG\")\n\n\nclass FileSplitReq(BaseModel):\n    \"\"\"\n    File splitting request model\n\n    Attributes:\n        file: File content or path, required\n        resourceType: Resource type, 0-regular file, 1-URL webpage, default is 0\n        ragType: RAG type\n        lengthRange: Split length range, optional\n        overlap: Overlap length, optional\n        separator: Separator list, optional\n        cutOff: Cutoff marker list, optional\n        titleSplit: Whether to split by title, default is False\n        documentId: Existing RAGFlow doc id for re-slice upsert, optional\n        group: Knowledge base group used by non-Ragflow strategies, optional\n        datasetId: RAGFlow dataset.id for direct routing, optional","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/domain/entity/chunk_dto.py#L22-L58","documentation":"ValueError raised by _require_group_for_non_ragflow: every RAG type except Ragflow-RAG (e.g. SparkDesk-RAG) mandates a non-empty group identifier, because those backends route retrieval by group. Ragflow-RAG is the only type that may omit it.","triggerScenarios":"A request DTO (e.g. FileSplitReq or chunk request) is built with rag_type set to anything other than RAGType.RagFlow_RAG while group is None or empty string — the validation helper called from _group_required_for_non_ragflow rejects it.","commonSituations":"Frontend hides the group field when users pick a non-Ragflow RAG type; default ragType switched (e.g. to SparkDesk-RAG) without collecting group; API consumers copying Ragflow payloads to other backends; group lost in form-to-DTO mapping.","solutions":["Provide the group field (the knowledge-base group ID issued for that RAG backend) whenever ragType != Ragflow-RAG.","If Ragflow is actually intended, explicitly set ragType='Ragflow-RAG' so group becomes optional.","Fix the frontend to show/require the group input for SparkDesk-RAG and other backends.","Check the DTO mapping to ensure group isn't dropped or defaulted to None during request construction."],"exampleFix":"// before\nreq = FileSplitReq(rag_type=RAGType.SparkDesk_RAG)  # group omitted -> ValueError\n// after\nreq = FileSplitReq(rag_type=RAGType.SparkDesk_RAG, group=\"my-spark-group\")\n# or, if no group is truly needed:\nreq = FileSplitReq(rag_type=RAGType.RagFlow_RAG)","handlingStrategy":"validation","validationCode":"def can_build_chunk_req(rag_type: str, group):\n    return bool(group) or rag_type == \"Ragflow-RAG\"\n# refuse to send the request until can_build_chunk_req(rag_type, group) is True","typeGuard":"def group_valid(rag_type: RAGType, group: Optional[str]) -> bool:\n    return rag_type == RAGType.RagFlow_RAG or bool(group and group.strip())","tryCatchPattern":"try:\n    submit_chunk_request(dto)\nexcept ValueError as e:\n    if \"group is required\" in str(e):\n        prompt_user_for_group()  # or fall back to Ragflow-RAG\n    else:\n        raise","preventionTips":["Validate the ragType/group pair in the form layer before submitting.","Make the group input conditionally required whenever a non-Ragflow backend is selected.","Mirror the backend rule in a shared client-side validator to catch drift early.","Never default group to empty string when a non-Ragflow ragType is set."],"tags":["validation","rag","knowledge","required-field"],"backgroundTag":"missing-required-argument","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}