{"record":{"id":"86622a73af95d9bc","repo":"vxcontrol/pentagi","slug":"knowledge-invalidrequest","errorCode":"Knowledge.InvalidRequest","errorMessage":"group field not found","messagePattern":"group field not found","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"backend/pkg/server/services/knowledge.go","lineNumber":194,"sourceCode":"\t\t\tWhere(\"langchain_pg_collection.name = ?\", \"langchain\").\n\t\t\tWhere(\"COALESCE(langchain_pg_embedding.cmetadata ->> 'doc_type', '') NOT IN (?)\", []string{\"memory\"})\n\t}\n\n\t// Authorization scope: admins see all documents; regular users see only their own.\n\tauthScope := func(db *gorm.DB) *gorm.DB {\n\t\tif admin {\n\t\t\treturn db\n\t\t}\n\t\treturn db.Where(\"(langchain_pg_embedding.cmetadata ->> 'user_id')::bigint = ?\", uid)\n\t}\n\n\t// ---- Grouped query -------------------------------------------------------\n\t// When a group field is requested the response is a list of distinct values\n\t// rather than full document rows (mirrors the pattern used in other services).\n\tif query.Group != \"\" {\n\t\tif _, ok := knowledgeSQLMappers[query.Group]; !ok {\n\t\t\tlogger.FromContext(c).Errorf(\"group field %q not found in knowledge mappers\", query.Group)\n\t\t\tresponse.Error(c, response.ErrKnowledgeInvalidRequest, errors.New(\"group field not found\"))\n\t\t\treturn\n\t\t}\n\n\t\tvar resp knowledgeGrouped\n\t\tvar err error\n\t\tif resp.Total, err = query.QueryGrouped(s.db, &resp.Grouped, baseScope, authScope); err != nil {\n\t\t\tlogger.FromContext(c).WithError(err).Error(\"error querying knowledge documents grouped\")\n\t\t\tresponse.Error(c, response.ErrInternal, err)\n\t\t\treturn\n\t\t}\n\n\t\tresponse.Success(c, http.StatusOK, resp)\n\t\treturn\n\t}\n\n\t// ---- Paginated / sorted query --------------------------------------------\n\n\t// Override the default \"ORDER BY id DESC\" — the PK column is uuid, not id.","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/services/knowledge.go#L176-L212","documentation":"ListDocuments in the knowledge service supports grouped queries. If query.Group names a field not present in knowledgeSQLMappers, the service returns this Knowledge.InvalidRequest error, mirroring the same group-validation pattern used in other services, to prevent grouping on unknown columns.","triggerScenarios":"GET knowledge documents list with ?group=<field> where <field> is not a key of knowledgeSQLMappers (typo, renamed column, or non-groupable field).","commonSituations":"Client-side faceted-search UI emitting stale field names after a schema change; copy-pasted group param from another service (flows/msglogs) whose mappers differ; camelCase vs snake_case mismatch.","solutions":["Use a field that exists in knowledgeSQLMappers (inspect pkg/server/services/knowledge.go).","Align the group parameter with the current knowledge schema field names.","If grouping was copied from another endpoint, verify each service has its own mapper set.","Add the field to knowledgeSQLMappers if grouping by it is a legitimate new requirement."],"exampleFix":"// before\nGET /knowledge/documents?group=documentType\n// after\nGET /knowledge/documents?group=document_type","handlingStrategy":"validation","validationCode":"const KNOWLEDGE_GROUPS = ['document_type','status','created_at']; // mirror knowledgeSQLMappers\nif (group && !KNOWLEDGE_GROUPS.includes(group)) {\n  throw new Error(`group field not found: ${group}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const docs = await listKnowledgeDocuments({ group });\n  render(docs);\n} catch (e) {\n  if (e.code === 'Knowledge.InvalidRequest' && /group field not found/.test(e.message)) {\n    clearGrouping();\n    notify('This field cannot be used for grouping documents.');\n  } else { throw e; }\n}","preventionTips":["Keep a shared, generated list of valid group fields per service.","Do not reuse group params across services; each has its own mappers.","Validate the group param in the client before the request.","Cover each exposed grouping option with an API test."],"tags":["validation","query-params","sql"],"backgroundTag":"invalid-group-field","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}