Skip to content

fix: exclude null fields from API payloads to match Node SDK behavior#169

Closed
dineshreddy91 wants to merge 1 commit intomainfrom
fix/exclude-none-fields-from-payload
Closed

fix: exclude null fields from API payloads to match Node SDK behavior#169
dineshreddy91 wants to merge 1 commit intomainfrom
fix/exclude-none-fields-from-payload

Conversation

@dineshreddy91
Copy link
Copy Markdown
Contributor

Summary

  • GenerationConfig.model_dump(): defaults to exclude_none=True so null fields like prompt, json_schema, gql_stmt and all null AgentSkill sub-fields (skill_id, name, source, bundle) are omitted. Always strips the internal response_model field (was only stripped when non-None before).
  • document.generate(): only includes domain in the payload when it has a value (previously always sent "domain": null). Same for callback_url.
  • execute() / image.generate(): same callback_url cleanup.

Before (Python SDK sent ~20 null fields):

{"prompt": null, "response_model": null, "json_schema": null, "gql_stmt": null, "max_retries": 3, ..., "skills": [{"type": "skill_reference", "skill_id": null, "skill_name": "invoice-extraction", "version": "latest", "name": null, "description": null, "source": null, "bundle": null}]}

After (matches Node SDK):

{"max_retries": 3, "max_tokens": 65535, "temperature": 0.0, "detail": "auto", "confidence": false, "grounding": false, "skills": [{"type": "skill_reference", "skill_name": "invoice-extraction", "version": "latest"}]}

Test plan

  • document.generate(domain="document.invoice", ...) — domain included in payload, works as before
  • document.generate(config=GenerationConfig(skills=[...])) — domain omitted from payload
  • GenerationConfig(response_model=MyModel).model_dump() — produces json_schema field, no response_model
  • GenerationConfig().model_dump() — no null fields in output

Made with Cursor

GenerationConfig.model_dump() was sending all null fields (response_model,
prompt, json_schema, etc.) and AgentSkill null fields (skill_id, name,
source, bundle) in every request. This caused bloated payloads with ~20
unnecessary null fields vs the Node SDK which omits them.

Changes:
- GenerationConfig.model_dump(): default to exclude_none=True, always
  strip the internal response_model field
- document.generate(): only include domain/callback_url when non-None
- execute()/image.generate(): same callback_url cleanup

Made-with: Cursor
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines the API payload generation across various client methods to prevent the transmission of null fields. By aligning the Python SDK's behavior with the Node SDK, it ensures that fields such as prompt, json_schema, gql_stmt, domain, and callback_url, along with sub-fields within AgentSkill objects, are only included in API requests when they hold meaningful values. This change results in cleaner, more efficient payloads and a consistent client experience.

Highlights

  • API Payload Optimization: The GenerationConfig.model_dump() method now defaults to exclude_none=True, ensuring that null fields are omitted from the generated payload. It also consistently strips the internal response_model field.
  • Conditional Field Inclusion: API calls for document.generate(), execute(), and image.generate() have been updated to conditionally include domain and callback_url in their request payloads only when these values are explicitly provided and not null.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the goal of excluding null fields from API payloads to align the Python SDK with the Node SDK's behavior. The changes across vlmrun/client/predictions.py correctly modify how request data is constructed, ensuring that optional fields like domain and callback_url are only included when they have a value. In vlmrun/client/types.py, the update to GenerationConfig.model_dump to default to exclude_none=True is a clean and robust solution for filtering out null values from the configuration.

The implementations are correct and improve code clarity.

One minor point for consideration in a future change: the execute method in ImagePredictions was not updated and still passes callback_url directly, which could result in sending null. This might be an oversight and could be updated for consistency.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant