go-playground/validator · error

Bad field name provided %s

Error message

Bad field name provided %s

What it means

Panics inside isUnique's default branch (non-slice fields) when the parent struct has no field whose name matches the unique tag parameter. parent.FieldByName(param) returns an invalid value, meaning the unique=OtherField tag references a sibling field that does not exist on the struct being validated — a tag configuration error, not a data error.

Source

Thrown at baked_in.go:480

					key = val.Elem().Interface() // <-- compare underlying value
				}
			} else {
				key = val.Interface()
			}

			if _, ok := seen[key]; ok {
				return false
			}
			seen[key] = struct{}{}
		}

		return true

	default:
		if parent := fl.Parent(); parent.Kind() == reflect.Struct {
			uniqueField := parent.FieldByName(param)
			if !uniqueField.IsValid() {
				panic(fmt.Sprintf("Bad field name provided %s", param))
			}

			if uniqueField.Kind() != field.Kind() {
				panic(fmt.Sprintf("Bad field type %s:%s", field.Type(), uniqueField.Type()))
			}

			return getValue(field) != getValue(uniqueField)
		}

		panic(fmt.Sprintf("Bad field type %s", field.Type()))
	}
}

// isMAC is the validation function for validating if the field's value is a valid MAC address.
func isMAC(fl FieldLevel) bool {
	_, err := net.ParseMAC(fl.Field().String())

	return err == nil

View on GitHub (pinned to facf128d2e)

Solutions

  1. Fix the unique tag parameter to reference an existing sibling field name (case-sensitive)
  2. Add the referenced field to the struct if it is missing
  3. Update unique tags whenever referenced fields are renamed
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at baked_in.go:480 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of go-playground/validator@facf128d2e (2026-09-02). Data as JSON: /api/errors/c9f1e0b9573902f5. Report an issue: GitHub.