openai/openai-python · error · ValueError

Expected a non-empty value for `user_id` but received {user_

Error message

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

What it means

Raised when `projects.users.retrieve` is called with an empty `user_id`. The SDK rejects empty path parameters client-side before constructing `/organization/projects/{project_id}/users/{user_id}`, so no request is sent.

Source

Thrown at src/openai/resources/admin/organization/projects/users/users.py:139

        extra_body: Body | None = None,
        timeout: float | httpx2.Timeout | None | NotGiven = not_given,
    ) -> ProjectUser:
        """
        Retrieves a user in the project.

        Args:
          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 user_id:
            raise ValueError(f"Expected a non-empty value for `user_id` but received {user_id!r}")
        return self._get(
            path_template(
                "/organization/projects/{project_id}/users/{user_id}", project_id=project_id, user_id=user_id
            ),
            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=ProjectUser,
        )

    def update(
        self,
        user_id: str,
        *,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Pass the real 'user_...' ID; if you only have an email, list project users and match on email first
  2. Check for None/empty results from any upstream lookup before calling retrieve
  3. Validate user-supplied IDs at the edge of your application

Example fix

# before
user = client.admin.organization.projects.users.retrieve(project_id=p, user_id=found_user_id)  # may be None
# after
if not found_user_id:
    raise LookupError("user not found")
user = client.admin.organization.projects.users.retrieve(project_id=p, user_id=found_user_id)
Defensive patterns

Strategy: validation

Validate before calling

if not user_id:
    raise LookupError("user not found; cannot retrieve")
user = client.admin.organization.projects.users.retrieve(project_id=project_id, user_id=user_id)

Type guard

def is_valid_user_id(v: object) -> bool:
    return isinstance(v, str) and bool(v.strip())

Prevention

When it happens

Trigger: Calling retrieve with user_id="" or None — e.g. after searching users and not finding a match, then passing the None result straight through.

Common situations: Chaining lookups where the user was not found, passing email instead of user ID, or empty rows from a database query.

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/14ccfcc64646ee58. Report an issue: GitHub.