symfony/http-kernel · error · LogicException

GroupSequence cannot be used inside an array of validation…

Error message

GroupSequence cannot be used inside an array of validation groups. Pass the GroupSequence as the top-level validationGroups value instead.

What it means

A GroupSequence is only accepted as the entire top-level validationGroups value. If a GroupSequence instance appears as an element inside an array of groups, Symfony throws this LogicException directing you to pass it at the top level.

Solutions

  1. Pass the GroupSequence directly as validationGroups (not inside an array)
  2. Fold the extra groups into the sequence itself
  3. Use GroupSequenceProvider on the DTO if dynamic sequencing is needed

Example fix

// before
validationGroups: [new GroupSequence(['A','B'])]
// after
validationGroups: new GroupSequence(['A','B'])
Defensive patterns

Strategy: validation

Validate before calling

foreach ($groups as $g) { if ($g instanceof GroupSequence) { throw new \InvalidArgumentException('sequence must be top-level'); } }

Type guard

$groups instanceof GroupSequence || (is_array($groups) && !in_array(false, array_map('is_string', $groups), true))

Try / catch

try { $response = $kernel->handle($request); } catch (\LogicException $e) { if (str_contains($e->getMessage(), 'GroupSequence cannot be used inside')) { /* move sequence to top level */ } throw $e; }

Prevention

When it happens

Trigger: Passing validationGroups: [new GroupSequence([...]), 'Other'] on #[MapRequestPayload] or #[MapQueryString].

Common situations: Trying to combine a sequence with additional standalone groups in one array — the resolver's contract only permits a top-level sequence or a flat string array.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13). Data as JSON: /api/errors/7e050979de24e7d9. Report an issue: GitHub.

Appendix: source

Thrown at Controller/ArgumentResolver/RequestPayloadValueResolver.php:353

        if (null === $validationGroups || \is_string($validationGroups) || $validationGroups instanceof GroupSequence) {
            return $validationGroups;
        }

        if (!\is_array($validationGroups)) {
            throw new \LogicException('The validation groups expression or closure must return a string, an array of strings, or a GroupSequence.');
        }

        foreach ($validationGroups as $group) {
            if ($group instanceof Expression) {
                throw new \LogicException('Nested expressions in validation groups are not supported. Use a single Expression or a list of strings (or a GroupSequence) instead.');
            }

            if ($group instanceof \Closure) {
                throw new \LogicException('Nested closures in validation groups are not supported. Use a single Closure or a list of strings (or a GroupSequence) instead.');
            }

            if ($group instanceof GroupSequence) {
                throw new \LogicException('GroupSequence cannot be used inside an array of validation groups. Pass the GroupSequence as the top-level validationGroups value instead.');
            }

            if (!\is_string($group)) {
                throw new \LogicException('Validation groups must be strings.');
            }
        }

        return $validationGroups;
    }

    private static function hasNonStringScalar(array $data): bool
    {
        $stack = [$data];

        while ($stack) {
            foreach (array_pop($stack) as $v) {
                if (\is_array($v)) {
                    $stack[] = $v;

View on GitHub (pinned to aa3a39d728)