larksuite/cli · error
object field has incompatible schema constraint
Error message
object field has incompatible schema constraint
What it means
A struct-typed field was tagged with schema constraints that only apply to scalars: enum values, string constraints, number constraints, item constraints, or format. Object shapes support field-level constraints via their own fields, so these tags describe an impossible combination and compilation is aborted.
Source
Thrown at shortcuts/common/typed_compile_data.go:157
}
if baseType.Elem().Kind() == reflect.Uint8 {
return nil, fmt.Errorf("byte slice or array %s requires an explicit Shape", baseType)
}
if len(schema.enum) > 0 || hasStringConstraints(schema) || hasNumberConstraints(schema) || schema.format != "" {
return nil, fmt.Errorf("array field has incompatible schema constraint")
}
elementSchema := schemaTag{required: true}
elementShape, err := shapeForType(baseType.Elem(), elementSchema, input, active)
if err != nil {
return nil, fmt.Errorf("array item: %w", err)
}
shape = typedArrayShape{Items: elementShape, MinItems: schema.minItems, MaxItems: schema.maxItems}
case reflect.Struct:
if implementsCustomEncoding(baseType) {
return nil, fmt.Errorf("custom JSON type %s requires an explicit Shape", baseType)
}
if len(schema.enum) > 0 || hasStringConstraints(schema) || hasNumberConstraints(schema) || hasItemConstraints(schema) || schema.format != "" {
return nil, fmt.Errorf("object field has incompatible schema constraint")
}
object, err := compileStructShape(baseType, input, baseType.String(), active)
if err != nil {
return nil, err
}
shape = object
case reflect.Map:
return nil, fmt.Errorf("map type %s requires an explicit Shape", baseType)
case reflect.Interface:
return nil, fmt.Errorf("interface type %s requires an explicit Shape", baseType)
default:
return nil, fmt.Errorf("Go type %s cannot be mapped to a ValueShape", t)
}
if schema.nullable != nil && *schema.nullable {
shape = typedOneOfShape{Variants: []typedValueShape{shape, typedNullShape{}}}
}
return shape, nil
}View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Remove the scalar-only constraint tags from the struct field.
- Apply the constraint to the relevant inner field of the struct instead.
- If a scalar is really intended, change the field type back (e.g. string) so the tag is valid.
- Alternatively supply an explicit Output.Data.Shape with the constraints placed where they apply.
Example fix
// before
type Owner struct {
ID string `json:"id"`
}
Owner Owner `json:"owner" schema:"format=uri"`
// after
Owner Owner `json:"owner"` // no scalar tags; constrain Owner.ID instead Defensive patterns
Strategy: validation
Validate before calling
func structTagsValid(f reflect.StructField) bool {
if f.Type.Kind() != reflect.Struct { return true }
tag := f.Tag.Get("schema")
for _, bad := range []string{"enum=", "format=", "minLength=", "maxLength=", "minimum=", "maximum=", "minItems=", "maxItems="} {
if strings.Contains(tag, bad) { return false }
}
return true
} Prevention
- Struct fields carry no scalar schema tags; constrain inner fields instead.
- Lint schema tags when refactoring a field from string to struct (or back).
- Code-review generated tags: generators often emit format= on every field.
When it happens
Trigger: A field like `someStruct `+"`"+`schema:"format=uri"`+"`"+` or `+"`"+`schema:"enum=a"`+"`"+` where the Go type is a struct reaches the reflect.Struct case in shapeForType.
Common situations: Schema tags copied from a neighboring string field; a generator adding format to every field; a field's Go type changed from string to struct without updating the tag.
Related errors
- array field has incompatible schema constraint
- Invalid column: {column!r}
- Invalid column index: {index}
- anchor outside sheet: {position!r}
- Missing row_count/column_count for sheet {sheet_title(sheet)
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/a740a9bb6f922cc6.
Report an issue: GitHub.