Skip to content

Why are so many schema fields nullable? #1008

@honnibal

Description

@honnibal

Let's say I call response = client.models.generate_content(...). I then might end up with an attribute access chain like response.candidates[0].content.parts[0].function_call.args. Pretty much all of these fields are nullable. I'd like to know when I need to handle these None values and what they would mean.

  • When will response.candidates be None?
  • When will response.candidates be an empty list?
  • When will candidate.content be None?
  • When will content.parts be None?
  • When will content.parts be an empty list?
  • (It's clear when part.function_call would be None)
  • When would function_call.args be None?

Thanks! LLM usage naturally involves a lot of error conditions from unexpected inputs, rate limits, timeouts etc. So I want to handle valid inputs as tightly as possible, so that I can track down what's happening better.

Activity

added
type: questionRequest for information or clarification. Not an issue.
priority: p3Desirable enhancement or fix. May not be included in next release.
on Jun 20, 2025
janasangeetha

janasangeetha commented on Jul 3, 2025

@janasangeetha
Collaborator

Hey @honnibal
Thank you for reaching out!
Please find the details below:

  • response.candidates can be None - if the API request itself failed before any candidates could be generated. This would typically indicate a problem with the request structure, authentication, or a server-side error unrelated to the content generation.
  • response.candidates will be an empty list - if the API request was successful but the model was unable to generate any valid candidates based on the prompt and parameters. This could happen if the prompt was too ambiguous, nonsensical, or if the safety filters blocked all potential responses.
  • candidate.content will be None - if the candidate represents a function call rather than a text or image response.
  • content.parts will be None - if the content itself is None. This would occur in the same scenarios where candidate.content is None.
  • content.parts will be an empty list - if the model generated a response but that response contained no actual content parts. This is less common but could theoretically occur if the model determined that no meaningful content could be generated based on the prompt, without triggering a complete failure or filter.
  • function_call.args will be None if the function call has no arguments. This is perfectly normal for functions that are defined to be called without any input parameters.
github-actions

github-actions commented on Jul 18, 2025

@github-actions

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @honnibal@janasangeetha

      Issue actions

        Why are so many schema fields nullable? · Issue #1008 · googleapis/python-genai