weaviate/weaviate · error

element [%d]: mismatched data type - '%s' expected, got refe

Error message

element [%d]: mismatched data type - '%s' expected, got reference

What it means

The reverse of the mixed-scalar case: the first element of an array property resolved to a scalar type (int, text, number, bool, date, etc.), but a later element was recognized as a reference to another collection. Auto-schema cannot mix references and scalars in one property, so it fails naming the scalar type it expected.

Source

Thrown at usecases/objects/auto_schema.go:329

					determinedDataType = schema.DataTypeTextArray
					continue
				}
				if determinedDataType == schema.DataTypeUUIDArray && (dataType == schema.DataTypeDateArray || dataType == schema.DataTypeTextArray) {
					determinedDataType = schema.DataTypeTextArray
					continue
				}

				if isRef {
					return nil, fmt.Errorf("element [%d]: mismatched data type - reference expected, got '%s'",
						i, asSingleDataType(dataType))
				}
				if dataType != determinedDataType {
					return nil, fmt.Errorf("element [%d]: mismatched data type - '%s' expected, got '%s'",
						i, asSingleDataType(determinedDataType), asSingleDataType(dataType))
				}
			} else {
				if !isRef {
					return nil, fmt.Errorf("element [%d]: mismatched data type - '%s' expected, got reference",
						i, asSingleDataType(determinedDataType))
				}
				refDataTypes = append(refDataTypes, refDataType)
			}
		}
		if len(refDataTypes) > 0 {
			return refDataTypes, nil
		}
		return []schema.DataType{determinedDataType}, nil
	case nil:
		return fallbackDataType, nil
	default:
		allowed := []string{
			schema.DataTypeText.String(),
			schema.DataTypeNumber.String(),
			schema.DataTypeInt.String(),
			schema.DataTypeBoolean.String(),
			schema.DataTypeDate.String(),

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. Remove the reference element or move references to a dedicated reference property.
  2. Ensure every element in the array is the scalar type inferred from the first element.
  3. Explicitly declare the property in the schema (scalar dataType) so reference values are rejected earlier with clearer validation.
  4. Audit payload-building code for places where beacons/objects can leak into scalar arrays.

Example fix

// before (scalar first, reference later)
{"items": ["label", {"beacon": "weaviate://Product/abc"}]}
// after
{"items": ["label"], "productRefs": [{"beacon": "weaviate://Product/abc"}]}
Defensive patterns

Strategy: validation

Validate before calling

func noReferencesInScalarArray(arr []interface{}) bool {
	for _, el := range arr {
		if _, isMap := el.(map[string]interface{}); isMap { return false }
	}
	return true
}

Type guard

func isReferenceValue(v interface{}) bool {
	m, ok := v.(map[string]interface{})
	return ok && m["beacon"] != nil
}

Prevention

When it happens

Trigger: POST /v1/objects with an array property whose first element is a scalar and a later element is a reference, e.g. {"items": ["text", {"beacon": "weaviate://Product/abc"}]}.

Common situations: Accidentally including beacon objects in a text/keyword array; join/merge logic appending foreign keys to an existing string array; migration scripts that reuse one field for both IDs and labels.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/8d5465886401dbda. Report an issue: GitHub.