SigNoz/signoz · error
failed to validate and cast value for %s: %v
Error message
failed to validate and cast value for %s: %v
What it means
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.
Source
Thrown at pkg/query-service/app/resource/resource_query_builder.go:237
// since out map is in lower case we are converting it to lowercase
operatorLower := strings.ToLower(string(item.Operator))
op := v3.FilterOperator(operatorLower)
keyName := item.Key.Key
// resource filter value data type will always be string
// will be an interface if the operator is IN or NOT IN
if item.Key.DataType != v3.AttributeKeyDataTypeString &&
(op != v3.FilterOperatorIn && op != v3.FilterOperatorNotIn) {
return nil, fmt.Errorf("invalid data type for resource attribute: %s", item.Key.Key)
}
var value interface{}
var err error
if op != v3.FilterOperatorExists && op != v3.FilterOperatorNotExists {
// make sure to cast the value regardless of the actual type
value, err = utils.ValidateAndCastValue(item.Value, item.Key.DataType)
if err != nil {
return nil, fmt.Errorf("failed to validate and cast value for %s: %v", item.Key.Key, err)
}
}
if logsOp, ok := resourceLogOperators[op]; ok {
members := []string{keyName}
if resolveSemconvFamilies {
members = semconv.Members(semconv.KindAttribute, telemetrytypes.FieldKeySelector{
Name: keyName,
Signal: telemetrytypes.SignalTraces,
FieldContext: telemetrytypes.FieldContextResource,
})
}
// the filter
if resourceFilter := buildResourceFilter(logsOp, keyName, op, value, members); resourceFilter != "" {
conditions = append(conditions, resourceFilter)
}
// the additional filter for better usage of the index
if resourceIndexFilter := buildResourceIndexFilter(keyName, op, value, members); resourceIndexFilter != "" {View on GitHub (pinned to 5069bf80b0)
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
Example fix
// before
{"key":{"key":"http.status_code","dataType":"int64"},"value":"200","operator":"="}
// after
{"key":{"key":"http.status_code","dataType":"int64"},"value":200,"operator":"="} Defensive patterns
Strategy: validation
Validate before calling
if _, err := utils.ValidateAndCastValue(item.Value, item.Key.DataType); err != nil {
return fmt.Errorf("fix value type for %s: %v", item.Key.Key, err)
} Type guard
func valueMatchesDataType(v interface{}, dt v3.AttributeKeyDataType) bool {
switch dt {
case v3.AttributeKeyDataTypeInt64, v3.AttributeKeyDataTypeFloat64:
_, ok := v.(float64)
return ok
case v3.AttributeKeyDataTypeBool:
_, ok := v.(bool)
return ok
default:
_, ok := v.(string)
return ok
}
} Prevention
- Validate filter values client-side against key DataTypes
- Use typed form inputs (number input for numeric attributes)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- invalid data type for resource attribute: %s
- unsupported operator: %s
- unsupported aggregate operator
- live tail is only supported for single query
- invalid value for key %s: %v
AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28).
Data as JSON: /api/errors/36d6ee606d55e700.
Report an issue: GitHub.