Skip to content

feat(google): add Model Armor support for Google Cloud via GoogleModelSettings#5691

Open
Alex-Resch wants to merge 3 commits into
pydantic:mainfrom
Alex-Resch:feature/google-model-armor-config
Open

feat(google): add Model Armor support for Google Cloud via GoogleModelSettings#5691
Alex-Resch wants to merge 3 commits into
pydantic:mainfrom
Alex-Resch:feature/google-model-armor-config

Conversation

@Alex-Resch
Copy link
Copy Markdown
Contributor

Summary

Adds google_model_armor_config to GoogleModelSettings, enabling users to configure Model Armor templates for screening prompts and responses when using GoogleCloudProvider.

Changes

  • Added google_model_armor_config field to GoogleModelSettings accepting a ModelArmorConfigDict with optional prompt_template_name and response_template_name
  • Raises UserError when google_model_armor_config is used with GoogleProvider (Gemini API), since Model Armor is only supported on Google Cloud
  • Extracted validation into _get_model_armor_config to keep _build_content_and_config within complexity limits
  • Added docs section for Model Armor in docs/models/google.md
  • Added three tests: VCR test for prompt blocking, mock test for response blocking (SPII finish reason), and unit test for the Gemini API UserError

Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • PR title is fit for the release changelog.

Copilot AI review requested due to automatic review settings May 27, 2026 18:34
@github-actions github-actions Bot added size: S Small PR (≤100 weighted lines) feature New feature request, or PR implementing a feature (enhancement) labels May 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_config to GoogleModelSettings and forward it as model_armor_config in 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 thread tests/models/test_google.py Outdated
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 thread tests/models/test_google.py Outdated
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 thread tests/models/test_google.py Outdated
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',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature request, or PR implementing a feature (enhancement) size: S Small PR (≤100 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support model armor config in Gemini

2 participants