[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3
SEQ. 4

System Instructions & Safety

✨ Mastering the Gemini API 15m 200 BASE XP⌨ HANDS-ON LAB

Steering Behavior & Enterprise Harm Filtering

In enterprise systems, production AI must remain tightly aligned with brand guidelines, regulatory boundaries, and deterministic output formats. Vertex AI provides two foundational primitives for governing model responses: System Instructions and Safety Filters.

System Instructions as Root Constraints

The systemInstruction parameter physically partitions persistent behavioral rules from the volatile conversation stream. Setting system instructions anchors the model's persona, mandates structural requirements (e.g. "Always respond in RFC 8259 JSON"), and establishes defense-in-depth against prompt injection attacks originating from untrusted user inputs.

Configuring Granular Harm Categories

Vertex AI provides 4 primary enterprise safety categories, each adjustable to BLOCK_NONE, BLOCK_ONLY_HIGH, BLOCK_MEDIUM_AND_ABOVE, or BLOCK_LOW_AND_ABOVE:

  • HARM_CATEGORY_HATE_SPEECH: Content targeting protected groups or identity attributes.
  • HARM_CATEGORY_DANGEROUS_CONTENT: Facilitating harm, malware generation, weaponization, or CBRN materials.
  • HARM_CATEGORY_HARASSMENT: Targeted bullying, disparagement, or intimidation.
  • HARM_CATEGORY_SEXUALLY_EXPLICIT: Explicit imagery or sexual content.
import { GoogleGenAI, HarmCategory, HarmBlockThreshold } from "@google/genai";

const ai = new GoogleGenAI({ vertexAI: true, project: "my-gcp-project", location: "us-central1" });

const response = await ai.models.generateContent({
  model: "gemini-3.8-flash",
  config: {
    systemInstruction: "You are a deterministic financial compliance auditor. Analyze claims strictly against GAAP standards.",
    safetySettings: [
      {
        category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
        threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
      },
      {
        category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
        threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
      }
    ]
  },
  contents: "Review this risk disclosure draft."
});

console.log(response.text);
⌨ HANDS-ON LABEnforce Vertex AI Safety Filter Thresholds
⭐ +150 XP

Configure strict harm category safety settings and system instructions on a Gemini foundation model call.

1Send a completion request with explicit BLOCK_LOW_AND_ABOVE thresholds for dangerous content.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 1 — type "hint" if stuck
SYNAPSE VERIFICATION
QUERY 1 // 4
What is the architectural purpose of passing instructions in the systemInstruction parameter?
It accelerates the model's GPU clock speed
It physically partitions developer behavioral rules from volatile user prompts to prevent prompt injection
It deletes user history after 5 minutes
It converts output text into XML