{"record":{"id":"cf7cc4ffb54a6019","repo":"symfony/http-kernel","slug":"the-validation-groups-expression-or-closure-must-return-a","errorCode":null,"errorMessage":"The validation groups expression or closure must return a string, an array of strings, or a GroupSequence.","messagePattern":"The validation groups expression or closure must return a string, an array of strings, or a GroupSequence\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Controller/ArgumentResolver/RequestPayloadValueResolver.php","lineNumber":340,"sourceCode":"        foreach ($files as $value) {\n            $params[] = $value;\n        }\n\n        return $params;\n    }\n\n    private function resolveValidationGroups(Expression|string|GroupSequence|\\Closure|array|null $validationGroups, ControllerArgumentsEvent $event): string|GroupSequence|array|null\n    {\n        if ($validationGroups instanceof Expression || $validationGroups instanceof \\Closure) {\n            $validationGroups = $event->evaluate($validationGroups, $this->expressionLanguage);\n        }\n\n        if (null === $validationGroups || \\is_string($validationGroups) || $validationGroups instanceof GroupSequence) {\n            return $validationGroups;\n        }\n\n        if (!\\is_array($validationGroups)) {\n            throw new \\LogicException('The validation groups expression or closure must return a string, an array of strings, or a GroupSequence.');\n        }\n\n        foreach ($validationGroups as $group) {\n            if ($group instanceof Expression) {\n                throw new \\LogicException('Nested expressions in validation groups are not supported. Use a single Expression or a list of strings (or a GroupSequence) instead.');\n            }\n\n            if ($group instanceof \\Closure) {\n                throw new \\LogicException('Nested closures in validation groups are not supported. Use a single Closure or a list of strings (or a GroupSequence) instead.');\n            }\n\n            if ($group instanceof GroupSequence) {\n                throw new \\LogicException('GroupSequence cannot be used inside an array of validation groups. Pass the GroupSequence as the top-level validationGroups value instead.');\n            }\n\n            if (!\\is_string($group)) {\n                throw new \\LogicException('Validation groups must be strings.');\n            }","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ArgumentResolver/RequestPayloadValueResolver.php#L322-L358","documentation":"resolveValidationGroups validates the groups computed from the validationGroups expression or closure of a payload attribute. If the callable/expression returns something that is not null, a string, an array, or a GroupSequence, Symfony throws this LogicException.","triggerScenarios":"A validationGroups closure or expression that returns e.g. an int, an object, or true instead of a string, string[], or GroupSequence instance.","commonSituations":"Expression strings that evaluate to numbers/booleans, closures returning wrong types after refactoring, or misunderstanding what validationGroups may yield.","solutions":["Make the closure/expression return a string, array of strings, or GroupSequence","Cast or normalize the returned value inside the closure","Remove validationGroups to use the default group"],"exampleFix":"// before\nvalidationGroups: fn() => 42\n// after\nvalidationGroups: fn() => ['Default']","handlingStrategy":"validation","validationCode":"$groups = $closure(); if (null !== $groups && !is_string($groups) && !is_array($groups) && !$groups instanceof GroupSequence) { throw new \\UnexpectedValueException('bad validationGroups return'); }","typeGuard":"is_string($groups) || is_array($groups) || $groups instanceof GroupSequence || $groups === null","tryCatchPattern":"try { $response = $kernel->handle($request); } catch (\\LogicException $e) { if (str_contains($e->getMessage(), 'validation groups expression')) { /* fix return type */ } throw $e; }","preventionTips":["Return types on validationGroups closures: ): ?array|string|GroupSequence","Keep expressions simple and test their evaluation","Document allowed group return shapes for your team"],"tags":["symfony","validation","groups","logic-exception"],"backgroundTag":"invalid-argument-value","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}