Google Cloud Model Armor is a service designed to enhance the security and safety of generative AI applications by proactively screening Large Language Model (LLM) prompts and responses. It protects against risks such as prompt injection, harmful content, and data leakage by allowing users to define policies and filters. The `google-cloud-modelarmor` Python client library provides programmatic access to this service. As of version 0.5.0, the library is in preview and under active development, with releases potentially introducing backwards-incompatible changes.
pip install google-cloud-modelarmorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate the Model Armor client and use it to sanitize a user prompt. It requires a Google Cloud project with the Model Armor API enabled, billing configured, and Application Default Credentials set up (e.g., via `gcloud auth application-default login`). You will also need to create a Model Armor template in your project and specify its ID, along with the project ID and location, as environment variables.
Review release notes and changelogs carefully before upgrading, especially for minor and patch versions. Pin exact version numbers in production environments.
Ensure your development and deployment environments use Python 3.9 or a newer supported version. Google Cloud client libraries frequently update Python version requirements, so monitor for future changes.
Follow the official Google Cloud authentication guide for Python client libraries. Verify that your environment has valid credentials before running your application.
Always specify the desired Google Cloud region when configuring Model Armor resources and ensure your client is configured to communicate with the correct regional endpoint. In the quickstart, this is handled via `client_options={'api_endpoint': ...}`.Implement careful log handling, especially for access restrictions, if logs are stored. Avoid building logic that depends on the exact content or format of log messages from this library.