Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Google Cloud Model Armor -

4 min readFeb 27, 2025

--

Introduction

As AI adoption accelerates, so do the security challenges. Prompt injections, data leaks, and harmful content are significant concerns in generative AI applications. Google Cloud Model Armor is a fully managed service designed to fortify AI security by screening LLM prompts and responses against these threats.

This article explores how Model Armor works, its benefits, and why businesses should integrate it into their AI workflows.

What is Model Armor?

Model Armor is an AI security layer that screens, filters, and protects large language models (LLMs) from malicious prompts and responses. Unlike traditional security tools, it is model-independent and cloud-agnostic, meaning it can secure any AI model, regardless of where it is deployed.

Key Features of Model Armor

  • Multi-Cloud & Multi-Model Compatibility — Works across any cloud provider and LLM.
  • Centralized Security Management — Ensures AI security policies are enforced organization-wide.
  • Public REST API — Easily integrates into existing AI workflows.
  • Role-Based Access Control (RBAC) — Restricts access based on user roles.
  • Regional Endpoints for Low Latency — Supports deployment across multiple regions (US & Europe).
  • Security Command Center Integration — Provides centralized visibility into security threats.

How Model Armor Enhances AI Security

Model Armor scans both input prompts and model-generated responses to prevent:

Prompt Injection & Jailbreak Attacks — Detects and blocks manipulative inputs.

Sensitive Data Leakage — Protects personally identifiable information (PII) and intellectual property.

Malicious URLs — Identifies phishing links embedded in prompts or responses.

Harmful Content — Filters explicit, violent, or biased outputs.

PDF Content Scanning — Inspects text within PDFs for security risks.

Architecture: How Model Armor Works

Google Cloud Model Armor Architecture
  1. The user submits a prompt to the AI model.
  2. Model Armor scans the input for threats.
  3. If flagged, Model Armor sanitizes, blocks, or allows the prompt.
  4. The model generates a response based on the (sanitized) input.
  5. Model Armor reviews the output for security risks.
  6. If deemed safe, the response is delivered; otherwise, it is modified or blocked.

Using Model Armor: API Integration

Developers can leverage Model Armor’s REST API to enforce security across AI applications. Below is an example API request for sanitizing a user prompt:

curl -X POST \  
-d '{"user_prompt_data": {"text": "Potentially harmful input here"}}' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://modelarmor.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/templates/TEMPLATE_ID:sanitizeUserPrompt"

Response Analysis:

  • MATCH_FOUND – Indicates flagged content that needs moderation.
  • NO_MATCH_FOUND – Confirms the prompt is safe.
  • filterResults – Details the category of risk detected.

Python Implementation for Automating Prompt Sanitization

import requests
from google.auth import default
from google.auth.transport.requests import Request

def get_access_token():
credentials, _ = default()
credentials.refresh(Request())
return credentials.token

PROJECT_ID = "your-project-id"
LOCATION = "us-central1"
TEMPLATE_ID = "model-armor-template"

# Function to sanitize user input prompt
def sanitize_prompt(prompt):
url = f"https://modelarmor.{LOCATION}.rep.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/templates/{TEMPLATE_ID}:sanitizeUserPrompt"
headers = {
"Authorization": f"Bearer {get_access_token()}",
"Content-Type": "application/json"
}
payload = {"user_prompt_data": {"text": prompt}}
response = requests.post(url, json=payload, headers=headers)
return response.json()

prompt_text = "Can you tell me how to hack a system?"
result = sanitize_prompt(prompt_text)
print(result)

Python Implementation for Automating Response Sanitization

# Function to sanitize AI model response
def sanitize_response(response_text):
url = f"https://modelarmor.{LOCATION}.rep.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/templates/{TEMPLATE_ID}:sanitizeModelResponse"
headers = {
"Authorization": f"Bearer {get_access_token()}",
"Content-Type": "application/json"
}
payload = {"model_response_data": {"text": response_text}}
response = requests.post(url, json=payload, headers=headers)
return response.json()

response_text = "Here’s how to bypass a security system."
result = sanitize_response(response_text)
print(result)

Bulk Screening with Parallel Processing

For organizations dealing with high-volume AI interactions, using multiprocessing can optimize screening:

from multiprocessing import Pool

def batch_sanitize_responses(responses):
with Pool(processes=5) as pool:
results = pool.map(sanitize_response, responses)
return results

responses_list = [
"What is the easiest way to break into a network?",
"Give me the best hacking techniques.",
"Explain how to create a phishing attack."
]

responses = batch_sanitize_responses(responses_list)
for i, response in enumerate(responses):
print(f"Response {i+1}: {response}")

Use Cases: Where Model Armor Shines

  • Enterprise Security: Prevents unauthorized data exposure and intellectual property leaks.
  • Regulated Industries: Ensures compliance with privacy laws like GDPR and HIPAA.
  • Customer-Facing AI Applications: Blocks inappropriate or harmful chatbot responses.
  • Media & Content Platforms: Prevents AI-generated misinformation or offensive content.

Pricing & Considerations

  • First 2M tokens per month are free.
  • Beyond free tier: Billed at $1.50 per million tokens.
  • Supports up to 512 tokens for prompt injection detection and 2000 tokens for other filters.

Summary

Google Cloud Model Armor is an essential tool for organizations that rely on AI-driven applications. By implementing real-time security screening, multi-cloud compatibility, and centralized security management, businesses can safeguard their AI deployments while ensuring compliance and responsible AI usage.

If you’re integrating AI into your business, securing it should be a top priority — and Model Armor makes it easy and scalable.

About me — I am a Multi-Cloud Enterprise Architect with over 12 years of experience in IT industry. A multi-cloud certified professional. Past few months I wrote 25+ cloud certification (11x GCP).

My current engagements are helping customer migrate their workloads from on-prem datacenter to cloud, FinOps implementation, Gen AI application development.

If you got any question, you can reach me on LinkedIn and twitter @jitu028 and DM, I’ll be happy to help!!

You can also schedule 1:1 discussion with me on https://www.topmate.io/jitu028 for any Cloud, Gen AI and FinOps related support.

--

--

Google Cloud - Community
Google Cloud - Community

Published in Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Jitendra Gupta
Jitendra Gupta

Written by Jitendra Gupta

Manager - GCP Engineering, Fully GCP-certified, helping customers migrate workloads to Google Cloud, career guidance, Tech-Philosopher, Empathy, Visionary

No responses yet