openai/openai-python · error · ValueError

Expected a non-empty value for `group_id` but received {grou

Error message

Expected a non-empty value for `group_id` but received {group_id!r}

What it means

Raised client-side by the openai-python SDK before any HTTP request. Assigning a role to a group via client.admin.organization.projects.groups.roles.create(...) requires a non-empty group_id because it forms /projects/{project_id}/groups/{group_id}/roles. An empty group_id would corrupt the URL path, so the SDK raises ValueError immediately with the received value.

Source

Thrown at src/openai/resources/admin/organization/projects/groups/roles.py:76

    ) -> RoleCreateResponse:
        """
        Assigns a project role to a group within a project.

        Args:
          role_id: Identifier of the role to assign.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if not project_id:
            raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
        if not group_id:
            raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
        return self._post(
            path_template("/projects/{project_id}/groups/{group_id}/roles", project_id=project_id, group_id=group_id),
            body=maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                security={"admin_api_key_auth": True},
            ),
            cast_to=RoleCreateResponse,
        )

    def retrieve(
        self,
        role_id: str,
        *,
        project_id: str,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Capture group.id from the groups.create(...) response and pass that exact value.
  2. Check that the group actually exists via groups.retrieve/list before assigning roles.
  3. Validate non-empty group_id and role_id before the call.

Example fix

# before
client.admin.organization.projects.groups.roles.create(project_id=pid, group_id=gid, role_id=rid)

# after
gid = group.id if group and group.id else None
if not gid:
    raise RuntimeError("group id missing; creation may have failed")
client.admin.organization.projects.groups.roles.create(project_id=pid, group_id=gid, role_id=rid)
Defensive patterns

Strategy: validation

Validate before calling

gid = group.id if group else None
if not gid:
    raise RuntimeError("group id missing; was the group created?")
client.admin.organization.projects.groups.roles.create(project_id=project_id, group_id=gid, role_id=role_id)

Type guard

def has_group_id(obj: object) -> bool:
    return obj is not None and isinstance(getattr(obj, "id", None), str) and bool(obj.id)

Try / catch

try:
    client.admin.organization.projects.groups.roles.create(project_id=pid, group_id=gid, role_id=rid)
except ValueError as e:
    if "group_id" in str(e):
        gid = client.admin.organization.projects.groups.retrieve(project_id=pid, group_id=known).id
    else:
        raise

Prevention

When it happens

Trigger: Calling roles.create(project_id=..., group_id='', role_id=...) where the group_id variable is None, an empty string, or a lookup result for a group that was never created/fetched.

Common situations: Creating a group and assigning its role in one flow but reading the id from the wrong response field; group creation failed silently upstream; ids parsed from malformed input files.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/a437b64cdbd8a4cc. Report an issue: GitHub.