SigNoz/signoz · error

invalid data type, expected string, got %v

Error message

invalid data type, expected string, got %v

What it means

ValidateAndCastValue, when the filter item's key DataType is string and the value is a []interface{}, coerces each element (string/float64/bool are formatted with %v). This error fires for an element of any other type — e.g. nil, map, or nested slice.

Source

Thrown at pkg/query-service/utils/format.go:42

		case string, int, int64, float32, float64, bool:
			return fmt.Sprintf("%v", x), nil
		case []interface{}:
			for i, val := range x {
				// if val is not string and it is int, int64, float, bool, convert it to string
				if _, ok := val.(string); ok {
					continue
				} else if _, ok := val.(int); ok {
					x[i] = fmt.Sprintf("%v", val)
				} else if _, ok := val.(int64); ok {
					x[i] = fmt.Sprintf("%v", val)
				} else if _, ok := val.(float32); ok {
					x[i] = fmt.Sprintf("%v", val)
				} else if _, ok := val.(float64); ok {
					x[i] = fmt.Sprintf("%v", val)
				} else if _, ok := val.(bool); ok {
					x[i] = fmt.Sprintf("%v", val)
				} else {
					return nil, fmt.Errorf("invalid data type, expected string, got %v", reflect.TypeOf(val))
				}
			}
			return x, nil
		case []string:
			return x, nil
		default:
			return nil, fmt.Errorf("invalid data type, expected string, got %v", reflect.TypeOf(v))
		}
	case v3.AttributeKeyDataTypeBool:
		switch x := v.(type) {
		case []interface{}:
			for i, val := range x {
				if _, ok := val.(string); ok {
					boolean, err := strconv.ParseBool(val.(string))
					if err != nil {
						return nil, fmt.Errorf("invalid data type, expected bool, got %v", reflect.TypeOf(val))
					}
					x[i] = boolean

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Send only scalar values (strings/numbers/booleans) in the value array for string-typed keys
  2. Filter out nulls client-side before submitting the query

Example fix

// before
{"value":[null,"frontend"]}
// after
{"value":["frontend"]}
Defensive patterns

Strategy: type-guard

Validate before calling

for _, el := range valueArr { switch el.(type) { case string, float64, bool: default: return fmt.Errorf("invalid element %T", el) } }

Type guard

func isScalarStringCastable(el interface{}) bool { switch el.(type) { case string, float64, bool: return true }; return false }

Prevention

When it happens

Trigger: Passing a filter value array like [null] or [{"a":1}] for an attribute whose data type is string; used by buildTracesFilterQuery / BuildTracesFilterQuery when constructing ClickHouse traces filters.

Common situations: JSON bodies with nulls in value arrays; clients sending nested objects as values; GraphQL/JSON-decoded []interface{} holding unexpected types.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/dbd721fc6469dbfd. Report an issue: GitHub.