---
title: "POST /v1/{+parent}/guardrails"
method: POST
path: "/v1/{+parent}/guardrails"
tags: ["projects"]
---

# POST /v1/{+parent}/guardrails

`POST /v1/{+parent}/guardrails`

Creates a new guardrail in the given app.

## Path parameters

- `parent` string, required

## Query parameters

- `guardrailId` string

## Request body

- Guardrail — Guardrail contains a list of checks and balances to keep the agents safe and secure.
  - `codeCallback` GuardrailCodeCallback — Guardrail that blocks the conversation based on the code callbacks provided.
    - `beforeAgentCallback` Callback — A callback defines the custom logic to be executed at various stages of agent interaction.
      - `pythonCode` string — Required. The python code to execute for the callback.
      - `description` string — Optional. Human-readable description of the callback.
      - `disabled` boolean — Optional. Whether the callback is disabled. Disabled callbacks are ignored by the agent.
      - `proactiveExecutionEnabled` boolean — Optional. If enabled, the callback will also be executed on intermediate model outputs. This setting only affects after model callback. **ENABLE WITH CAUTION**. Typically after model callback only needs to be executed after receiving all model responses. Enabling proactive execution may have negative implication on the execution cost and latency, and should only be enabled in rare situations.
    - `afterAgentCallback` Callback — A callback defines the custom logic to be executed at various stages of agent interaction.
      - `pythonCode` string — Required. The python code to execute for the callback.
      - `description` string — Optional. Human-readable description of the callback.
      - `disabled` boolean — Optional. Whether the callback is disabled. Disabled callbacks are ignored by the agent.
      - `proactiveExecutionEnabled` boolean — Optional. If enabled, the callback will also be executed on intermediate model outputs. This setting only affects after model callback. **ENABLE WITH CAUTION**. Typically after model callback only needs to be executed after receiving all model responses. Enabling proactive execution may have negative implication on the execution cost and latency, and should only be enabled in rare situations.
    - `beforeModelCallback` Callback — A callback defines the custom logic to be executed at various stages of agent interaction.
      - `pythonCode` string — Required. The python code to execute for the callback.
      - `description` string — Optional. Human-readable description of the callback.
      - `disabled` boolean — Optional. Whether the callback is disabled. Disabled callbacks are ignored by the agent.
      - `proactiveExecutionEnabled` boolean — Optional. If enabled, the callback will also be executed on intermediate model outputs. This setting only affects after model callback. **ENABLE WITH CAUTION**. Typically after model callback only needs to be executed after receiving all model responses. Enabling proactive execution may have negative implication on the execution cost and latency, and should only be enabled in rare situations.
    - `afterModelCallback` Callback — A callback defines the custom logic to be executed at various stages of agent interaction.
      - `pythonCode` string — Required. The python code to execute for the callback.
      - `description` string — Optional. Human-readable description of the callback.
      - `disabled` boolean — Optional. Whether the callback is disabled. Disabled callbacks are ignored by the agent.
      - `proactiveExecutionEnabled` boolean — Optional. If enabled, the callback will also be executed on intermediate model outputs. This setting only affects after model callback. **ENABLE WITH CAUTION**. Typically after model callback only needs to be executed after receiving all model responses. Enabling proactive execution may have negative implication on the execution cost and latency, and should only be enabled in rare situations.
  - `etag` string — Etag used to ensure the object hasn't changed during a read-modify-write operation. If the etag is empty, the update will overwrite any concurrent changes.
  - `enabled` boolean — Optional. Whether the guardrail is enabled.
  - `action` TriggerAction — Action that is taken when a certain precondition is met.
    - `respondImmediately` TriggerActionRespondImmediately — The agent will immediately respond with a preconfigured response.
      - `responses` TriggerActionResponse[] — Required. The canned responses for the agent to choose from. The response is chosen randomly.
        - `disabled` boolean — Optional. Whether the response is disabled. Disabled responses are not used by the agent.
        - `text` string — Required. Text for the agent to respond with.
    - `transferAgent` TriggerActionTransferAgent — The agent will transfer the conversation to a different agent.
      - `agent` string — Required. The name of the agent to transfer the conversation to. The agent must be in the same app as the current agent. Format: `projects/{project}/locations/{location}/apps/{app}/agents/{agent}`
    - `generativeAnswer` TriggerActionGenerativeAnswer — The agent will immediately respond with a generative answer.
      - `prompt` string — Required. The prompt to use for the generative answer.
  - `modelSafety` GuardrailModelSafety — Model safety settings overrides. When this is set, it will override the default settings and trigger the guardrail if the response is considered unsafe.
    - `safetySettings` GuardrailModelSafetySafetySetting[] — Required. List of safety settings.
      - `category` 'HARM_CATEGORY_UNSPECIFIED' | 'HARM_CATEGORY_HATE_SPEECH' | 'HARM_CATEGORY_DANGEROUS_CONTENT' | 'HARM_CATEGORY_HARASSMENT' | 'HARM_CATEGORY_SEXUALLY_EXPLICIT' — Required. The harm category.
      - `threshold` 'HARM_BLOCK_THRESHOLD_UNSPECIFIED' | 'BLOCK_LOW_AND_ABOVE' | 'BLOCK_MEDIUM_AND_ABOVE' | 'BLOCK_ONLY_HIGH' | 'BLOCK_NONE' | 'OFF' — Required. The harm block threshold.
  - `displayName` string — Required. Display name of the guardrail.
  - `contentFilter` GuardrailContentFilter — Guardrail that bans certain content from being used in the conversation.
    - `matchType` 'MATCH_TYPE_UNSPECIFIED' | 'SIMPLE_STRING_MATCH' | 'WORD_BOUNDARY_STRING_MATCH' | 'REGEXP_MATCH' — Required. Match type for the content filter.
    - `bannedContentsInUserInput` string[] — Optional. List of banned phrases. Applies only to user inputs.
    - `bannedContents` string[] — Optional. List of banned phrases. Applies to both user inputs and agent responses.
    - `bannedContentsInAgentResponse` string[] — Optional. List of banned phrases. Applies only to agent responses.
    - `disregardDiacritics` boolean — Optional. If true, diacritics are ignored during matching.
  - `llmPolicy` GuardrailLlmPolicy — Guardrail that blocks the conversation if the LLM response is considered violating the policy based on the LLM classification.
    - `maxConversationMessages` integer — Optional. When checking this policy, consider the last 'n' messages in the conversation. When not set a default value of 10 will be used.
    - `modelSettings` ModelSettings — Model settings contains various configurations for the LLM model.
      - `temperature` number, double — Optional. If set, this temperature will be used for the LLM model. Temperature controls the randomness of the model's responses. Lower temperatures produce responses that are more predictable. Higher temperatures produce responses that are more creative.
      - `model` string — Optional. The LLM model that the agent should use. If not set, the agent will inherit the model from its parent agent.
    - `allowShortUtterance` boolean — Optional. By default, the LLM policy check is bypassed for short utterances. Enabling this setting applies the policy check to all utterances, including those that would normally be skipped.
    - `prompt` string — Required. Policy prompt.
    - `policyScope` 'POLICY_SCOPE_UNSPECIFIED' | 'USER_QUERY' | 'AGENT_RESPONSE' | 'USER_QUERY_AND_AGENT_RESPONSE' — Required. Defines when to apply the policy check during the conversation. If set to `POLICY_SCOPE_UNSPECIFIED`, the policy will be applied to the user input. When applying the policy to the agent response, additional latency will be introduced before the agent can respond.
    - `failOpen` boolean — Optional. If an error occurs during the policy check, fail open and do not trigger the guardrail.
  - `llmPromptSecurity` GuardrailLlmPromptSecurity — Guardrail that blocks the conversation if the input is considered unsafe based on the LLM classification.
    - `defaultSettings` GuardrailLlmPromptSecurityDefaultSecuritySettings — Configuration for default system security settings.
      - `defaultPromptTemplate` string — Output only. The default prompt template used by the system. This field is for display purposes to show the user what prompt the system uses by default. It is OUTPUT_ONLY.
    - `customPolicy` GuardrailLlmPolicy — Guardrail that blocks the conversation if the LLM response is considered violating the policy based on the LLM classification.
      - `maxConversationMessages` integer — Optional. When checking this policy, consider the last 'n' messages in the conversation. When not set a default value of 10 will be used.
      - `modelSettings` ModelSettings — Model settings contains various configurations for the LLM model.
        - `temperature` number, double — Optional. If set, this temperature will be used for the LLM model. Temperature controls the randomness of the model's responses. Lower temperatures produce responses that are more predictable. Higher temperatures produce responses that are more creative.
        - `model` string — Optional. The LLM model that the agent should use. If not set, the agent will inherit the model from its parent agent.
      - `allowShortUtterance` boolean — Optional. By default, the LLM policy check is bypassed for short utterances. Enabling this setting applies the policy check to all utterances, including those that would normally be skipped.
      - `prompt` string — Required. Policy prompt.
      - `policyScope` 'POLICY_SCOPE_UNSPECIFIED' | 'USER_QUERY' | 'AGENT_RESPONSE' | 'USER_QUERY_AND_AGENT_RESPONSE' — Required. Defines when to apply the policy check during the conversation. If set to `POLICY_SCOPE_UNSPECIFIED`, the policy will be applied to the user input. When applying the policy to the agent response, additional latency will be introduced before the agent can respond.
      - `failOpen` boolean — Optional. If an error occurs during the policy check, fail open and do not trigger the guardrail.
    - `failOpen` boolean — Optional. Determines the behavior when the guardrail encounters an LLM error. - If true: the guardrail is bypassed. - If false (default): the guardrail triggers/blocks. Note: If a custom policy is provided, this field is ignored in favor of the policy's 'fail_open' configuration.
  - `description` string — Optional. Description of the guardrail.
  - `updateTime` string, google-datetime — Output only. Timestamp when the guardrail was last updated.
  - `createTime` string, google-datetime — Output only. Timestamp when the guardrail was created.
  - `name` string — Identifier. The unique identifier of the guardrail. Format: `projects/{project}/locations/{location}/apps/{app}/guardrails/{guardrail}`

## Response `200`

Successful response

---

[API](https://skmtc.net/google/apis/ces.md) · [All operations](https://skmtc.net/google/apis/ces/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/google/ces/versions/429598666166/schema)
