Responsible AI — Best Practices
Distilled from 4 notebooks tagged Responsible AI in the GoogleCloudPlatform/generative-ai repository. The From the notebooks section below cites the per-notebook source for grounding.
Do this
- Be concise, specific, and well-defined in prompts.
- Ask one task at a time to reduce ambiguity and output variability.
- Use system instructions to guardrail the model away from irrelevant or unsafe responses.
- Convert generative tasks into classification tasks when lower variability is important.
- Use zero-shot, one-shot, or few-shot prompting based on the goal, with one to five representative examples.
- Keep example distribution aligned with the real distribution for classification tasks.
- State that provided context is the only source of truth when grounding matters.
- For long documents or data, place the question after the context and ask the model to answer based on the full document above.
- For complex prompts, place the most important constraints at the end.
- Use persona carefully because it can override other instructions.
- Inspect safety_ratings and finish_reason instead of relying only on generated text.
- Set safety thresholds according to business policies and use case needs.
- Check both input and output with DLP before sending content to Gemini or returning content to users.
- Treat user-provided links, binaries, files, retrieved documents, and tool data as untrusted and validate them.
- Use defense in depth: combine safety filters, DLP, embeddings-based dangerous-prompt detection, mission checks, schema validation, OCR when needed, and user consent for dangerous operations.
Avoid this
- Assuming Gemini has real-time information without additional integrations, which can lead to confident hallucinations.
- Treating prompted citations as a reliable hallucination fix, even though citations can be false or inaccurate.
- Using too many examples, which can overfit the prompt and reduce response quality.
- Ignoring response metadata such as safety_ratings and finish_reason, especially when response.text is empty because filters blocked output.
- Turning safety filters to BLOCK_NONE outside a demonstration context.
- Relying on simple regex ReAct parsing or small embedding datasets as production-grade security controls.
- Assuming Cloud DLP catches all sensitive data, including transformed or encoded values.
- Forgetting required setup such as Google Cloud project configuration, Vertex AI API enablement, Colab authentication, quota project setup, or dependency/runtime restarts.
From the notebooks
Prompt Design - Best Practices
- Be concise in prompts.
- Be specific and well-defined.
- Ask one task at a time.
- Use system instructions to guardrail the model from irrelevant responses.
- Turn generative tasks into classification tasks to reduce output variability.
Gen AI & LLM Security for developers
- Do not store sensitive information in the prompt.
- Use low temperature for reproducible results in security demonstrations.
- Check both input and output with DLP before sending to or returning from Gemini.
- Treat links, binaries, and files from users as untrusted and validate them.
- Use Responsible AI safety filters and understand how to configure safety attributes.
Responsible AI with Gemini API in Vertex AI: Safety ratings and thresholds
- Inspect safety_ratings instead of relying only on generated text.
- Test prompts against safety categories before deployment.
- Set safety thresholds according to business policies and use case needs.
- Use low-variability generation settings when comparing safety behavior.
- Check finish_reason to understand why generation stopped.
Gen AI and LLM Security - ReAct and RAG attacks & mitigations
- Use ready Agents and RAG libraries such as Agent Builder, LangChain Agents, Vertex AI Search, and LangChain RAG.
- Use strict schema validation of tool input and output.
- Use out-of-band user consent for dangerous operations.
- Apply defense in depth by layering multiple filters.
- Use OCR for documents if concerned about invisible text.
Back to Responsible AI · Best Practices Map