Configuration for Model Armor integrations.
This feature is only supported in Vertex AI, not the Gemini Developer API.
Model Armor allows you to apply content filtering templates managed separately from your generation requests. This provides centralized policy management for content moderation.
Important
If model_armor_config is provided, safety_settings must NOT be provided.
These two options are mutually exclusive.
Fields
prompt_template_name- Resource name of the Model Armor template to apply to prompt content (optional)response_template_name- Resource name of the Model Armor template to apply to response content (optional)
Example
config = %Gemini.Types.ModelArmorConfig{
prompt_template_name: "projects/my-project/locations/us-central1/templates/prompt-filter",
response_template_name: "projects/my-project/locations/us-central1/templates/response-filter"
}
# Use in generate request (Vertex AI only)
Gemini.generate("Hello world", model_armor_config: config)
Summary
Functions
Creates a ModelArmorConfig from API response.
Creates a new ModelArmorConfig struct.
Converts ModelArmorConfig to API format (camelCase keys).
Validates that model_armor_config and safety_settings are not both provided.
Types
@type t() :: %Gemini.Types.ModelArmorConfig{ prompt_template_name: String.t() | nil, response_template_name: String.t() | nil }
Model Armor configuration.
prompt_template_name- Model Armor template for filtering prompt contentresponse_template_name- Model Armor template for filtering response content
Functions
Creates a ModelArmorConfig from API response.
Parameters
data- Map from API response with camelCase string keys
Creates a new ModelArmorConfig struct.
Parameters
opts- Keyword list with configuration options::prompt_template_name- Template name for prompt filtering:response_template_name- Template name for response filtering
Examples
config = Gemini.Types.ModelArmorConfig.new(
prompt_template_name: "projects/my-project/locations/us-central1/templates/t1"
)
Converts ModelArmorConfig to API format (camelCase keys).
Examples
config = %ModelArmorConfig{
prompt_template_name: "t1",
response_template_name: "t2"
}
ModelArmorConfig.to_api(config)
#=> %{"promptTemplateName" => "t1", "responseTemplateName" => "t2"}
@spec validate_exclusivity(t() | nil, list() | nil, :gemini | :vertex_ai) :: :ok | {:error, String.t()}
Validates that model_armor_config and safety_settings are not both provided.
This is a helper for request building - these options are mutually exclusive.
Parameters
model_armor_config- The model armor config (or nil)safety_settings- The safety settings list (or nil/empty)api_type- Current API type (:geminior:vertex_ai)
Returns
:ok- Validation passed{:error, reason}- Validation failed
Examples
validate_exclusivity(%ModelArmorConfig{...}, [], :vertex_ai)
#=> :ok
validate_exclusivity(%ModelArmorConfig{...}, [%SafetySetting{}], :vertex_ai)
#=> {:error, "model_armor_config and safety_settings are mutually exclusive"}
validate_exclusivity(%ModelArmorConfig{...}, nil, :gemini)
#=> {:error, "model_armor_config is only supported in Vertex AI"}