{"record":{"id":"3a323ec8477cad80","repo":"SigNoz/signoz","slug":"invalid-value-for-key-s-v","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/v3/query_builder.go","lineNumber":161,"sourceCode":"\t}\n\treturn int64(math.Pow(10, float64(19-count)))\n}\n\nfunc buildTracesFilterQuery(fs *v3.FilterSet) (string, error) {\n\tvar conditions []string\n\n\tif fs != nil && len(fs.Items) != 0 {\n\t\tfor _, item := range fs.Items {\n\t\t\tval := item.Value\n\t\t\t// generate the key\n\t\t\tcolumnName := getColumnName(item.Key)\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\tval = utils.QuoteEscapedString(fmt.Sprintf(\"%v\", item.Value))\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\n\t\t\t\t\t\t}","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/traces/v3/query_builder.go#L143-L179","documentation":"buildTracesFilterQuery (v3 traces builder) failed to validate/cast a filter value against the key's DataType via utils.ValidateAndCastValue. The message names the key and nests the underlying cast error, meaning the value's type does not match the declared attribute type.","triggerScenarios":"Sending a traces filter set where e.g. duration_ns (int64) receives \"1.5s\" or a string, or a bool key receives a non-boolean, with any operator other than exists/not exists.","commonSituations":"Hand-written API payloads with stringified numbers; stale filter sets saved before an attribute's dataType changed; frontend sending untyped input for numeric fields.","solutions":["Match the JSON value type to item.Key.DataType (numbers for int64/float64, bool for bool, string for string)","Re-fetch attribute keys to get current DataTypes and rebuild the filter","For exists/not-exists semantics, use those operators instead of supplying a dummy value"],"exampleFix":"// before\n{\"key\":{\"key\":\"duration_ns\",\"dataType\":\"int64\"},\"value\":\"abc\",\"operator\":\">\"}\n\n// after\n{\"key\":{\"key\":\"duration_ns\",\"dataType\":\"int64\"},\"value\":1000000,\"operator\":\">\"}","handlingStrategy":"validation","validationCode":"if item.Operator != v3.FilterOperatorExists && item.Operator != v3.FilterOperatorNotExists {\n    if _, err := utils.ValidateAndCastValue(item.Value, item.Key.DataType); err != nil {\n        return fmt.Errorf(\"invalid value for %s\", item.Key.Key)\n    }\n}","typeGuard":"func isCastsClean(v interface{}, dt v3.AttributeKeyDataType) bool {\n    _, err := utils.ValidateAndCastValue(v, dt)\n    return err == nil\n}","tryCatchPattern":null,"preventionTips":["Type filter values per attribute DataType before sending","Periodically refresh attribute metadata to catch type changes"],"tags":["signoz","traces","filters","type-casting","validation"],"backgroundTag":"value-type-cast-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}