{"record":{"id":"36d6ee606d55e700","repo":"SigNoz/signoz","slug":"failed-to-validate-and-cast-value-for-s-v","errorCode":null,"errorMessage":"failed to validate and cast value for %s: %v","messagePattern":"failed to validate and cast value for (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/query-service/app/resource/resource_query_builder.go","lineNumber":237,"sourceCode":"\t\t// since out map is in lower case we are converting it to lowercase\n\t\toperatorLower := strings.ToLower(string(item.Operator))\n\t\top := v3.FilterOperator(operatorLower)\n\t\tkeyName := item.Key.Key\n\n\t\t// resource filter value data type will always be string\n\t\t// will be an interface if the operator is IN or NOT IN\n\t\tif item.Key.DataType != v3.AttributeKeyDataTypeString &&\n\t\t\t(op != v3.FilterOperatorIn && op != v3.FilterOperatorNotIn) {\n\t\t\treturn nil, fmt.Errorf(\"invalid data type for resource attribute: %s\", item.Key.Key)\n\t\t}\n\n\t\tvar value interface{}\n\t\tvar err error\n\t\tif op != v3.FilterOperatorExists && op != v3.FilterOperatorNotExists {\n\t\t\t// make sure to cast the value regardless of the actual type\n\t\t\tvalue, err = utils.ValidateAndCastValue(item.Value, item.Key.DataType)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to validate and cast value for %s: %v\", item.Key.Key, err)\n\t\t\t}\n\t\t}\n\n\t\tif logsOp, ok := resourceLogOperators[op]; ok {\n\t\t\tmembers := []string{keyName}\n\t\t\tif resolveSemconvFamilies {\n\t\t\t\tmembers = semconv.Members(semconv.KindAttribute, telemetrytypes.FieldKeySelector{\n\t\t\t\t\tName:         keyName,\n\t\t\t\t\tSignal:       telemetrytypes.SignalTraces,\n\t\t\t\t\tFieldContext: telemetrytypes.FieldContextResource,\n\t\t\t\t})\n\t\t\t}\n\t\t\t// the filter\n\t\t\tif resourceFilter := buildResourceFilter(logsOp, keyName, op, value, members); resourceFilter != \"\" {\n\t\t\t\tconditions = append(conditions, resourceFilter)\n\t\t\t}\n\t\t\t// the additional filter for better usage of the index\n\t\t\tif resourceIndexFilter := buildResourceIndexFilter(keyName, op, value, members); resourceIndexFilter != \"\" {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/resource/resource_query_builder.go#L219-L255","documentation":"Wraps a failure from utils.ValidateAndCastValue while preparing a resource filter: the supplied filter value cannot be converted to the key's declared DataType. The wrapper message names the offending key and includes the underlying cast error.","triggerScenarios":"Passing a filter value like 'abc' for a key typed as int64/float64/bool, an empty or malformed array for IN operators, or a JSON-decoded value whose Go type conflicts with the declared data type.","commonSituations":"Frontend sends the raw string from an input box for a numeric attribute; API clients construct FilterItem JSON by hand with mismatched types; saved filters after an attribute's type changed.","solutions":["Send the value in the type matching item.Key.DataType (number for numeric keys, bool for bool keys)","Quote string values and use arrays for IN/NOT IN","If the attribute type changed recently, refresh the attribute keys so the client uses the current DataType"],"exampleFix":"// before\n{\"key\":{\"key\":\"http.status_code\",\"dataType\":\"int64\"},\"value\":\"200\",\"operator\":\"=\"}\n\n// after\n{\"key\":{\"key\":\"http.status_code\",\"dataType\":\"int64\"},\"value\":200,\"operator\":\"=\"}","handlingStrategy":"validation","validationCode":"if _, err := utils.ValidateAndCastValue(item.Value, item.Key.DataType); err != nil {\n    return fmt.Errorf(\"fix value type for %s: %v\", item.Key.Key, err)\n}","typeGuard":"func valueMatchesDataType(v interface{}, dt v3.AttributeKeyDataType) bool {\n    switch dt {\n    case v3.AttributeKeyDataTypeInt64, v3.AttributeKeyDataTypeFloat64:\n        _, ok := v.(float64)\n        return ok\n    case v3.AttributeKeyDataTypeBool:\n        _, ok := v.(bool)\n        return ok\n    default:\n        _, ok := v.(string)\n        return ok\n    }\n}","tryCatchPattern":null,"preventionTips":["Validate filter values client-side against key DataTypes","Use typed form inputs (number input for numeric attributes)"],"tags":["signoz","logs","resource-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"}