From eb3a7b15aebc1315a2d5af6ce0f8c972fd18f0bd Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Wed, 6 May 2026 15:45:33 -0700 Subject: [PATCH] feat(interaction-api): Add ModelArmorConfig to Interaction proto. FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/googleapis/python-genai/pull/2380 from googleapis:release-please--branches--main 10645e4b1dc44bb5c1ee35c215c9436af10b204e PiperOrigin-RevId: 911590846 --- .../_interactions/resources/interactions.py | 40 ++++++++++++- google/genai/_interactions/types/__init__.py | 2 + .../genai/_interactions/types/interaction.py | 6 ++ .../types/interaction_create_params.py | 7 +++ .../_interactions/types/model_armor_config.py | 58 +++++++++++++++++++ .../types/model_armor_config_param.py | 58 +++++++++++++++++++ 6 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 google/genai/_interactions/types/model_armor_config.py create mode 100644 google/genai/_interactions/types/model_armor_config_param.py diff --git a/google/genai/_interactions/resources/interactions.py b/google/genai/_interactions/resources/interactions.py index bdd1c5353..2545d3c33 100644 --- a/google/genai/_interactions/resources/interactions.py +++ b/google/genai/_interactions/resources/interactions.py @@ -22,7 +22,10 @@ import httpx -from ..types import interaction_get_params, interaction_create_params +from ..types import ( + interaction_get_params, + interaction_create_params, +) from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from .._utils import required_args, maybe_transform, async_maybe_transform from .._compat import cached_property @@ -41,6 +44,7 @@ from ..types.webhook_config_param import WebhookConfigParam from ..types.interaction_sse_event import InteractionSSEEvent from ..types.generation_config_param import GenerationConfigParam +from ..types.model_armor_config_param import ModelArmorConfigParam __all__ = ["InteractionsResource", "AsyncInteractionsResource"] @@ -74,6 +78,7 @@ def create( model: ModelParam, background: bool | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -103,6 +108,8 @@ def create( generation_config: Input only. Configuration parameters for the model interaction. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -145,6 +152,7 @@ def create( stream: Literal[True], background: bool | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -175,6 +183,8 @@ def create( generation_config: Input only. Configuration parameters for the model interaction. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -221,6 +231,7 @@ def create( input: interaction_create_params.Input, agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -250,6 +261,8 @@ def create( background: Input only. Whether to run the model interaction in the background. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -299,6 +312,7 @@ def create( stream: Literal[True], agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -329,6 +343,8 @@ def create( background: Input only. Whether to run the model interaction in the background. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -369,6 +385,7 @@ def create( stream: bool, background: bool | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -399,6 +416,8 @@ def create( generation_config: Input only. Configuration parameters for the model interaction. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -438,6 +457,7 @@ def create( model: ModelParam | Omit = omit, background: bool | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -481,6 +501,7 @@ def create( "model": model, "background": background, "generation_config": generation_config, + "model_armor_config": model_armor_config, "previous_interaction_id": previous_interaction_id, "response_format": response_format, "response_mime_type": response_mime_type, @@ -770,6 +791,7 @@ async def create( model: ModelParam, background: bool | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -799,6 +821,8 @@ async def create( generation_config: Input only. Configuration parameters for the model interaction. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -841,6 +865,7 @@ async def create( stream: Literal[True], background: bool | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -871,6 +896,8 @@ async def create( generation_config: Input only. Configuration parameters for the model interaction. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -917,6 +944,7 @@ async def create( input: interaction_create_params.Input, agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -946,6 +974,8 @@ async def create( background: Input only. Whether to run the model interaction in the background. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -995,6 +1025,7 @@ async def create( stream: Literal[True], agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -1025,6 +1056,8 @@ async def create( background: Input only. Whether to run the model interaction in the background. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -1065,6 +1098,7 @@ async def create( stream: bool, background: bool | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -1095,6 +1129,8 @@ async def create( generation_config: Input only. Configuration parameters for the model interaction. + model_armor_config: Settings for prompt and response sanitization using the Model Armor service. + previous_interaction_id: The ID of the previous interaction, if any. response_format: Enforces that the generated response is a JSON object that complies with the @@ -1134,6 +1170,7 @@ async def create( model: ModelParam | Omit = omit, background: bool | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model_armor_config: ModelArmorConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, @@ -1177,6 +1214,7 @@ async def create( "model": model, "background": background, "generation_config": generation_config, + "model_armor_config": model_armor_config, "previous_interaction_id": previous_interaction_id, "response_format": response_format, "response_mime_type": response_mime_type, diff --git a/google/genai/_interactions/types/__init__.py b/google/genai/_interactions/types/__init__.py index d3e4de38e..86a37b8f5 100644 --- a/google/genai/_interactions/types/__init__.py +++ b/google/genai/_interactions/types/__init__.py @@ -58,6 +58,7 @@ from .model_output_step import ModelOutputStep as ModelOutputStep from .function_call_step import FunctionCallStep as FunctionCallStep from .image_config_param import ImageConfigParam as ImageConfigParam +from .model_armor_config import ModelArmorConfig as ModelArmorConfig from .text_content_param import TextContentParam as TextContentParam from .thought_step_param import ThoughtStepParam as ThoughtStepParam from .tool_choice_config import ToolChoiceConfig as ToolChoiceConfig @@ -98,6 +99,7 @@ from .webhook_delete_response import WebhookDeleteResponse as WebhookDeleteResponse from .code_execution_call_step import CodeExecutionCallStep as CodeExecutionCallStep from .function_call_step_param import FunctionCallStepParam as FunctionCallStepParam +from .model_armor_config_param import ModelArmorConfigParam as ModelArmorConfigParam from .tool_choice_config_param import ToolChoiceConfigParam as ToolChoiceConfigParam from .google_search_result_step import GoogleSearchResultStep as GoogleSearchResultStep from .interaction_create_params import InteractionCreateParams as InteractionCreateParams diff --git a/google/genai/_interactions/types/interaction.py b/google/genai/_interactions/types/interaction.py index 233b6d68f..52194f56e 100644 --- a/google/genai/_interactions/types/interaction.py +++ b/google/genai/_interactions/types/interaction.py @@ -19,6 +19,8 @@ from datetime import datetime from typing_extensions import Literal, Annotated, TypeAlias +from pydantic import Field as FieldInfo + from .step import Step from .tool import Tool from .model import Model @@ -32,6 +34,7 @@ from .video_content import VideoContent from .webhook_config import WebhookConfig from .document_content import DocumentContent +from .model_armor_config import ModelArmorConfig from .dynamic_agent_config import DynamicAgentConfig from .text_response_format import TextResponseFormat from .audio_response_format import AudioResponseFormat @@ -104,6 +107,9 @@ class Interaction(BaseModel): model: Optional[Model] = None """The name of the `Model` used for generating the interaction.""" + api_model_armor_config: Optional[ModelArmorConfig] = FieldInfo(alias="model_armor_config", default=None) + """Settings for prompt and response sanitization using the Model Armor service.""" + previous_interaction_id: Optional[str] = None """The ID of the previous interaction, if any.""" diff --git a/google/genai/_interactions/types/interaction_create_params.py b/google/genai/_interactions/types/interaction_create_params.py index 3c13e4b90..757055ab9 100644 --- a/google/genai/_interactions/types/interaction_create_params.py +++ b/google/genai/_interactions/types/interaction_create_params.py @@ -31,6 +31,7 @@ from .webhook_config_param import WebhookConfigParam from .document_content_param import DocumentContentParam from .generation_config_param import GenerationConfigParam +from .model_armor_config_param import ModelArmorConfigParam from .dynamic_agent_config_param import DynamicAgentConfigParam from .text_response_format_param import TextResponseFormatParam from .audio_response_format_param import AudioResponseFormatParam @@ -67,6 +68,9 @@ class BaseCreateModelInteractionParams(TypedDict, total=False): generation_config: GenerationConfigParam """Input only. Configuration parameters for the model interaction.""" + model_armor_config: ModelArmorConfigParam + """Settings for prompt and response sanitization using the Model Armor service.""" + previous_interaction_id: str """The ID of the previous interaction, if any.""" @@ -151,6 +155,9 @@ class BaseCreateAgentInteractionParams(TypedDict, total=False): background: bool """Input only. Whether to run the model interaction in the background.""" + model_armor_config: ModelArmorConfigParam + """Settings for prompt and response sanitization using the Model Armor service.""" + previous_interaction_id: str """The ID of the previous interaction, if any.""" diff --git a/google/genai/_interactions/types/model_armor_config.py b/google/genai/_interactions/types/model_armor_config.py new file mode 100644 index 000000000..82fc7073c --- /dev/null +++ b/google/genai/_interactions/types/model_armor_config.py @@ -0,0 +1,58 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from pydantic import Field as FieldInfo + +from .._models import BaseModel + +__all__ = ["ModelArmorConfig"] + + +class ModelArmorConfig(BaseModel): + """Configuration for Model Armor. + + Model Armor is a Google Cloud service that provides safety and security + filtering for prompts and responses. It helps protect your AI applications + from risks such as harmful content, sensitive data leakage, and prompt + injection attacks. + """ + + prompt_template_name: Optional[str] = FieldInfo(alias="promptTemplateName", default=None) + """The resource name of the Model Armor template to use for prompt screening. + + A Model Armor template is a set of customized filters and thresholds that define + how Model Armor screens content. If specified, Model Armor will use this + template to check the user's prompt for safety and security risks before it is + sent to the model. + + The name must be in the format + `projects/{project}/locations/{location}/templates/{template}`. + """ + + response_template_name: Optional[str] = FieldInfo(alias="responseTemplateName", default=None) + """The resource name of the Model Armor template to use for response screening. + + A Model Armor template is a set of customized filters and thresholds that define + how Model Armor screens content. If specified, Model Armor will use this + template to check the model's response for safety and security risks before it + is returned to the user. + + The name must be in the format + `projects/{project}/locations/{location}/templates/{template}`. + """ diff --git a/google/genai/_interactions/types/model_armor_config_param.py b/google/genai/_interactions/types/model_armor_config_param.py new file mode 100644 index 000000000..069a631c1 --- /dev/null +++ b/google/genai/_interactions/types/model_armor_config_param.py @@ -0,0 +1,58 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Annotated, TypedDict + +from .._utils import PropertyInfo + +__all__ = ["ModelArmorConfigParam"] + + +class ModelArmorConfigParam(TypedDict, total=False): + """Configuration for Model Armor. + + Model Armor is a Google Cloud service that provides safety and security + filtering for prompts and responses. It helps protect your AI applications + from risks such as harmful content, sensitive data leakage, and prompt + injection attacks. + """ + + prompt_template_name: Annotated[str, PropertyInfo(alias="promptTemplateName")] + """The resource name of the Model Armor template to use for prompt screening. + + A Model Armor template is a set of customized filters and thresholds that define + how Model Armor screens content. If specified, Model Armor will use this + template to check the user's prompt for safety and security risks before it is + sent to the model. + + The name must be in the format + `projects/{project}/locations/{location}/templates/{template}`. + """ + + response_template_name: Annotated[str, PropertyInfo(alias="responseTemplateName")] + """The resource name of the Model Armor template to use for response screening. + + A Model Armor template is a set of customized filters and thresholds that define + how Model Armor screens content. If specified, Model Armor will use this + template to check the model's response for safety and security risks before it + is returned to the user. + + The name must be in the format + `projects/{project}/locations/{location}/templates/{template}`. + """