feat(google): add Model Armor support for Google Cloud via GoogleModelSettings#5691
Open
Alex-Resch wants to merge 3 commits into
Open
feat(google): add Model Armor support for Google Cloud via GoogleModelSettings#5691Alex-Resch wants to merge 3 commits into
Alex-Resch wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Google Cloud (Vertex AI) Model Armor support to GoogleModel, enabling prompt/response screening via Model Armor templates and providing tests + docs to validate and explain the feature.
Changes:
- Add
google_model_armor_configtoGoogleModelSettingsand forward it asmodel_armor_configin generation requests (Cloud-only). - Add tests for prompt blocking (VCR) and response blocking (mocked), plus a misuse guard for Gemini API providers.
- Document how to configure Model Armor in the Google model docs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/models/test_google.py | Adds fixtures and tests verifying Model Armor blocking + provider restriction behavior. |
| tests/models/cassettes/test_google/test_google_model_armor_prompt_template_text_gets_blocked.yaml | Records a blocked prompt interaction to validate Model Armor prompt screening. |
| pydantic_ai_slim/pydantic_ai/models/google.py | Introduces google_model_armor_config, validates provider, and passes config through to the SDK request. |
| docs/models/google.md | Documents Model Armor usage and configuration (Google Cloud only). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+848
to
+856
| def _get_model_armor_config(self, model_settings: GoogleModelSettings) -> ModelArmorConfigDict | None: | ||
| """Return model_armor_config, raising UserError if used with a non-Cloud provider.""" | ||
| model_armor_config = model_settings.get('google_model_armor_config') | ||
| if model_armor_config and self.system not in _GOOGLE_CLOUD_PROVIDER_NAMES: | ||
| raise UserError( | ||
| 'google_model_armor_config is only supported with GoogleCloudProvider (Google Cloud / Vertex AI). ' | ||
| 'Model Armor is not available in the Gemini API.' | ||
| ) | ||
| return model_armor_config |
Comment on lines
+6596
to
+6601
| return GoogleModelSettings( | ||
| google_model_armor_config={ | ||
| 'prompt_template_name': 'projects/pydantic-ai/locations/europe-west4/templates/prompt-template', | ||
| 'response_template_name': 'projects/pydantic-ai/locations/europe-west4/templates/response-template', | ||
| } | ||
| ) |
Comment on lines
+6659
to
+6662
| assert kwargs.get('config')['model_armor_config'] == { | ||
| 'prompt_template_name': 'projects/pydantic-ai/locations/europe-west4/templates/prompt-template', | ||
| 'response_template_name': 'projects/pydantic-ai/locations/europe-west4/templates/response-template', | ||
| } |
Comment on lines
+6659
to
+6662
| assert kwargs.get('config')['model_armor_config'] == { | ||
| 'prompt_template_name': 'projects/pydantic-ai/locations/europe-west4/templates/prompt-template', | ||
| 'response_template_name': 'projects/pydantic-ai/locations/europe-west4/templates/response-template', | ||
| } |
… model armor validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
google_model_armor_configtoGoogleModelSettings, enabling users to configure Model Armor templates for screening prompts and responses when usingGoogleCloudProvider.Changes
google_model_armor_configfield toGoogleModelSettingsaccepting aModelArmorConfigDictwith optionalprompt_template_nameandresponse_template_nameUserErrorwhengoogle_model_armor_configis used withGoogleProvider(Gemini API), since Model Armor is only supported on Google Cloud_get_model_armor_configto keep_build_content_and_configwithin complexity limitsdocs/models/google.mdUserErrorChecklist