ruby-grape/grape · error · Grape::Exceptions::UnsupportedGroupType
group type must be Array, Hash, JSON or Array[JSON]
Error message
group type must be Array, Hash, JSON or Array[JSON]
What it means
For a required parameter group, new_scope validates the declared type with Grape::Validations::Types.group? - only Array, Hash, JSON, and Array[JSON] can govern a block scope. Any other type (String, Integer, a custom class) raises Grape::Exceptions::UnsupportedGroupType ('group type must be Array, Hash, JSON or Array[JSON]') because Grape cannot interpret the block's members inside that container.
Source
Thrown at lib/grape/validations/params_scope.rb:283
def validate_attributes(attrs, **opts, &block)
opts[:type] ||= Array if block
validates(attrs, opts)
end
# Returns a new parameter scope, subordinate to the current one and nested
# under the given element.
# @param element [Symbol] the parameter name under which this scope is nested
# @param type [Class] the type governing this scope
# @param as [Symbol, nil] optional renamed name for the element
# @param optional [Boolean] whether the parameter this scope is nested under
# is optional or not (and hence, whether this block's params will be).
# @yield parameter scope
def new_scope(element, type:, as:, optional: false, &)
# if required params are grouped and no type or unsupported type is provided, raise an error
if element && !optional
raise Grape::Exceptions::MissingGroupType if type.nil?
raise Grape::Exceptions::UnsupportedGroupType unless Grape::Validations::Types.group?(type)
end
self.class.new(
api: @api,
element:,
element_renamed: as,
parent: self,
optional:,
type: type || Array,
group: @group,
&
)
end
# Returns a new parameter scope, not nested under any current-level param
# but instead at the same level as the current scope.
# @param dependent_on [Symbol] if given, specifies that this scope should
# only validate if this parameter from the above scope is presentView on GitHub (pinned to 22d7975629)
Solutions
- Use a group type: `type: Hash`, `type: Array`, `type: JSON`, or `type: Array[JSON]`.
- Remove the block if the parameter is a scalar or scalar array: `requires :tags, type: Array[String]`.
- For JSON payloads use `type: JSON` and declare members in the block.
Example fix
# before requires :tags, type: String do requires :name, type: String end # raises UnsupportedGroupType # after requires :tags, type: Array do requires :name, type: String end # scalar array without a block requires :tags, type: Array[String]
Defensive patterns
Strategy: type-guard
Validate before calling
def group_type_ok?(type) = Grape::Validations::Types.group?(type) raise ArgumentError, 'block params need Array, Hash, JSON or Array[JSON]' unless group_type_ok?(declared_type)
Type guard
def group_type?(type) = Grape::Validations::Types.group?(type)
Prevention
- Blocks only with group types; scalars and Array[Scalar] without blocks.
- When converting a scalar param to a group, change the type in the same edit.
- Boot specs per endpoint catch UnsupportedGroupType early.
When it happens
Trigger: `requires :tags, type: String do ... end`. `requires :items, type: Integer do ... end`. `requires :meta, type: SomeCustomClass do ... end` where the class is not one of the four group types.
Common situations: Changing a scalar parameter into a nested group but keeping the old scalar type. Mixing up `type: Array[String]` (valid only without a block) with block-based member declarations. Adapting examples with the wrong container type.
Related errors
- group type must be Array, Hash, JSON or Array[JSON]
- group type is required
- type #{type} should support coercion via `[]`
- group type is required
- #declared is not available prior to parameter validation
AI-assisted analysis of ruby-grape/grape@22d7975629 (2026-08-21).
Data as JSON: /api/errors/662d8e9f4d5ce0cc.
Report an issue: GitHub.