{"record":{"id":"f518cddb8592238d","repo":"SigNoz/signoz","slug":"invalid-value-for-key-s-v-f518cd","errorCode":null,"errorMessage":"invalid value for key %s: %v","messagePattern":"invalid value for key (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/query-service/app/traces/v4/query_builder.go","lineNumber":126,"sourceCode":"\tif fs != nil && len(fs.Items) != 0 {\n\t\tfor _, item := range fs.Items {\n\n\t\t\t// skip if it's a resource attribute or Span search scope attribute\n\t\t\t// adding skipAllowed because traceFunnels requires the resource one as well.\n\t\t\tif skipAllowed && (item.Key.Type == v3.AttributeKeyTypeResource || item.Key.Type == v3.AttributeKeyTypeSpanSearchScope) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tval := item.Value\n\t\t\t// generate the key\n\t\t\tcolumnName := getColumnName(item.Key, true)\n\t\t\tvar fmtVal string\n\t\t\titem.Operator = v3.FilterOperator(strings.ToLower(strings.TrimSpace(string(item.Operator))))\n\t\t\tif item.Operator != v3.FilterOperatorExists && item.Operator != v3.FilterOperatorNotExists {\n\t\t\t\tvar err error\n\t\t\t\tval, err = utils.ValidateAndCastValue(val, item.Key.DataType)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn \"\", fmt.Errorf(\"invalid value for key %s: %v\", item.Key.Key, err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif val != nil {\n\t\t\t\tfmtVal = utils.ClickHouseFormattedValue(val)\n\t\t\t}\n\t\t\tif operator, ok := tracesOperatorMappingV3[item.Operator]; ok {\n\t\t\t\tswitch item.Operator {\n\t\t\t\tcase v3.FilterOperatorContains, v3.FilterOperatorNotContains:\n\t\t\t\t\t// we also want to treat %, _ as literals for contains\n\t\t\t\t\tval := utils.QuoteEscapedStringForContains(fmt.Sprintf(\"%s\", item.Value), false)\n\t\t\t\t\tconditions = append(conditions, fmt.Sprintf(\"%s %s '%%%s%%'\", columnName, operator, val))\n\t\t\t\tcase v3.FilterOperatorRegex, v3.FilterOperatorNotRegex:\n\t\t\t\t\tconditions = append(conditions, fmt.Sprintf(operator, columnName, fmtVal))\n\t\t\t\tcase v3.FilterOperatorExists, v3.FilterOperatorNotExists:\n\t\t\t\t\tif item.Key.IsColumn {\n\t\t\t\t\t\tsubQuery, err := existsSubQueryForFixedColumn(item.Key, item.Operator)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn \"\", err","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/traces/v4/query_builder.go#L108-L144","documentation":"BuildTracesFilterQuery (v4 traces builder) failed to validate/cast a filter value against the key's declared DataType via utils.ValidateAndCastValue. The named key's value could not be converted, so the filter cannot be rendered into ClickHouse SQL.","triggerScenarios":"A traces FilterSet where a value's JSON/Go type conflicts with item.Key.DataType (string sent for int64 key, etc.) with any operator except exists/nexists. This function backs ValidateTraces, funnel analytics, step analytics, and slowest/errored trace endpoints, so those endpoints surface it too.","commonSituations":"Funnel or step-analytics payloads with hand-built filters; stringified numbers from client forms; attribute dataType drift after re-ingestion.","solutions":["Send values whose type matches item.Key.DataType","Validate the filter set client-side before calling these endpoints","Refresh attribute metadata to get accurate DataTypes"],"exampleFix":"// before\n{\"key\":{\"key\":\"status_code\",\"dataType\":\"int64\"},\"value\":\"500\"}\n\n// after\n{\"key\":{\"key\":\"status_code\",\"dataType\":\"int64\"},\"value\":500}","handlingStrategy":"validation","validationCode":"for _, item := range fs.Items {\n    if item.Operator != v3.FilterOperatorExists && item.Operator != v3.FilterOperatorNexists {\n        if _, err := utils.ValidateAndCastValue(item.Value, item.Key.DataType); err != nil {\n            return fmt.Errorf(\"fix value for %s\", item.Key.Key)\n        }\n    }\n}","typeGuard":"func filtersCastClean(fs *v3.FilterSet) bool {\n    for _, it := range fs.Items {\n        if _, err := utils.ValidateAndCastValue(it.Value, it.Key.DataType); err != nil {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["Validate funnel/step analytics payloads against attribute types","Use typed inputs in forms"],"tags":["signoz","traces","v4","filters","type-casting"],"backgroundTag":"value-type-cast-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}