# Example Helm values for deploying Guardrails as a Traffic Extension for GKE Inference Gateway.

# -- Top level guardrails configs.
guardrails:
  # -- The number of replicas for the NeMo Guardrails microservice deployment.
  replicaCount: 1
  # -- Configure the image for the main Guardrails container.
  image:
    # -- The repository location of the NeMo Guardrails container image.
    repository: nvcr.io/nvidia/nemo-microservices/guardrails
    # -- The tag of the NeMo Guardrails container image.
    tag: ""
  # -- Configure Guardrails MS's environment variables.
  env:
    # Disable DEMO mode for production.
    DEMO: "False"
    # Disable NIM_ENDPOINT_URL because Guardrails don't need to talk to main LLMs.
    NIM_ENDPOINT_URL: ""
    # Because we disabled NIM_ENDPOINT_URL, we also don't need to fetch any models.
    FETCH_NIM_APP_MODELS: "False"
    # Default config used when guardrails field is empty, e.g. "guardrails": {}
    DEFAULT_CONFIG_ID: default/nemoguard

  # Envoy External Processor for Taffic Extension. This is deployed as a sidecar next to the main Guardrails container.
  guardrailsExtProc:
    enabled: true
    extProcImage:
      # -- Repository for Guardrails ExtProc server image.
      repository: nvcr.io/nvidia/nemo-microservices/guardrails-callout
      # -- The tag of the Guardrails ExtProc container image.
      tag: ""
    # -- Configure the extproc sidecar's environment variables.
    env:
      # GR_EXTPROC__EVENTS_PER_CHECK controls how many chat completion chunks to buffer before checking.
      # Only relevant when processing streaming chat completion chunks.
      GR_EXTPROC__EVENTS_PER_CHECK: 200
    # -- More complex configurations go into a config file.
    configFile:
      # -- Everything under data is loaded as a file in a ConfigMap.
      data:
        guardrails:
          # -- The default refusal text for all models
          default_refusal_text: "I'm sorry, I can't respond to that."
          # -- Map model name to its relevant configs
          models:
            # Model names match the model name in the chat completion request.
            # fake-model is just an example, override it with your own, or add more models below
            fake-model:
              # -- Custom refusal text for this model, overrides the default_refusal_text above.
              refusal_text: "I'm sorry, I can't respond to that."
              # -- A list of guardrails config_ids to be used by this model. Must match the names in the configStore below.
              # If this is blank, then extproc will defer to Guardrails MS' DEFAULT_CONFIG_ID
              config_ids:
              - default/nemoguard
  # -- Configure GKE speicifc resources like Gateway and GCPTrafficExtension.
  gke:
    # -- Specify an existing Gateway. If a name is provided, the chart will not create a new Gateway.
    # IMPORTANT: The GCPTrafficExtension must be in the same namespace as the Gateway it targets.
    # Ensure you install this Helm chart in the same namespace as your existing Gateway.
    existingGateway: ""
    # -- Configuration for the Gateway created by this chart.
    gateway:
      # -- Enable or disable the creation of the Gateway.
      enabled: true
      # -- The name of the Gateway resource.
      name: "guardrailed-inference-gateway"
      # -- The GatewayClass to use. For GKE: gke-l7-gxlb (External), gke-l7-rilb (Internal).
      gatewayClassName: "gke-l7-rilb"
      # -- A list of listeners for the Gateway.
      listeners:
        - name: "http"
          port: 80
          protocol: "HTTP"
          hostname: ""
        # Example for an HTTPS listener:
        # - name: "https"
        #   port: 443
        #   protocol: "HTTPS"
        #   hostname: "secure.example.com"
        #   tls:
        #     mode: "Terminate"
        #     # A list of Kubernetes Secrets containing the TLS certificates.
        #     certificateRefs:
        #       - name: "secure-example-com-cert"
    # -- Configure the GCPTrafficExtension. Required for Guardrails to plug into the Gateway.
    extension:
      # -- Enable or disable the GCPTrafficExtension.
      enabled: true

  # -- Configure Guardrails MS's Config Store, which is a directory containing relevant config files.
  configStore:
    files:
      # Top-level config for main LLMs.
      "config.yaml":
        data:
          # NOTE: when Guardrails is deployed as a service extension, Guardrails don't actually call these models.
          models: []

      # Guardrails framework configuration files.
      # Each file belongs to a specific guardrails config identified by the directory containing it.
      # Note that all directories under the config-store belong to the `default` namespace.

      # config_id: default/nemoguard (use this in the guardrailsExtProc.configFile.guardrails.models[*].config_ids)
      "nemoguard/config.yaml":
        data:
          # -- Configure OpenTelemetry tracing in the Guardrails SDK. Note this is different from tracing in the Guardrails Microservice above.
          # Enhances the observability of guardrails execution.
          tracing:
            enabled: true
            adapters:
            - name: OpenTelemetry # default
          models:
          - type: content_safety
            engine: nim
            model: llama-3.1-nemoguard-8b-content-safety
            parameters:
              # base_url is used to talk to the content_safety NIM
              base_url: http://content-safety-nim-llm:8000/v1
          - type: topic_control
            engine: nim
            model: llama-3.1-nemoguard-8b-topic-control
            parameters:
              # base_url is used to talk to the topic-control NIM
              base_url: http://topic-control-nim-llm:8000/v1
          rails:
            input:
              parallel: false
              flows:
              - content safety check input $model=content_safety
              - topic safety check input $model=topic_control
            output:
              parallel: false
              flows:
              - content safety check output $model=content_safety
          prompts:
          - task: content_safety_check_input $model=content_safety
            content: |
              Task: Check if there is unsafe content in the user or agent messages in the below conversation in accordance with our safety policy with the below categories. Provide a 'safe' or 'unsafe' rating for both the user message and the agent response. If there is unsafe content, please also provide a list of violated categories according to our safety policy below.

              <BEGIN UNSAFE CONTENT CATEGORIES>
              S1: Violence.
              S2: Sexual.
              S3: Criminal Planning/Confessions.
              S4: Guns and Illegal Weapons.
              S5: Controlled/Regulated Substances.
              S6: Suicide and Self Harm.
              S7: Sexual (minor).
              S8: Hate/Identity Hate.
              S9: PII/Privacy.
              S10: Harassment.
              S11: Threat.
              S12: Profanity.
              S13: Needs Caution.
              S14: Other.
              S15: Manipulation.
              S16: Fraud/Deception.
              S17: Malware.
              S18: High Risk Gov Decision Making.
              S19: Political/Misinformation/Conspiracy.
              S20: Copyright/Trademark/Plagiarism.
              S21: Unauthorized Advice.
              S22: Illegal Activity.
              S23: Immoral/Unethical.
              <END UNSAFE CONTENT CATEGORIES>

              <BEGIN CONVERSATION>

              user: {{ user_input }}

              <END CONVERSATION>

              Provide your safety assessment for the above conversation in the below output JSON format:
              {"User Safety": safe or unsafe rating for the user message, "Response Safety": safe or unsafe rating for the agent response. Omit if no agent response present. "Safety Categories": a comma-separated list of applicable safety categories from the provided taxonomy. Omit if all safe.}

              Do not include anything other than the output JSON in your response.
              Output JSON:
            output_parser: nemoguard_parse_prompt_safety
            max_tokens: 50

          - task: content_safety_check_output $model=content_safety
            content: |
              Task: Check if there is unsafe content in the user or agent messages in the below conversation in accordance with our safety policy with the below categories. Provide a 'safe' or 'unsafe' rating for both the user message and the agent response. If there is unsafe content, please also provide a list of violated categories according to our safety policy below.

              <BEGIN UNSAFE CONTENT CATEGORIES>
              S1: Violence.
              S2: Sexual.
              S3: Criminal Planning/Confessions.
              S4: Guns and Illegal Weapons.
              S5: Controlled/Regulated Substances.
              S6: Suicide and Self Harm.
              S7: Sexual (minor).
              S8: Hate/Identity Hate.
              S9: PII/Privacy.
              S10: Harassment.
              S11: Threat.
              S12: Profanity.
              S13: Needs Caution.
              S14: Other.
              S15: Manipulation.
              S16: Fraud/Deception.
              S17: Malware.
              S18: High Risk Gov Decision Making.
              S19: Political/Misinformation/Conspiracy.
              S20: Copyright/Trademark/Plagiarism.
              S21: Unauthorized Advice.
              S22: Illegal Activity.
              S23: Immoral/Unethical.
              <END UNSAFE CONTENT CATEGORIES>

              <BEGIN CONVERSATION>

              user: {{ user_input }}

              response: agent: {{ bot_response }}

              <END CONVERSATION>

              Provide your safety assessment for the above conversation in the below output JSON format:
              {"User Safety": safe or unsafe rating for the user message, "Response Safety": safe or unsafe rating for the agent response. Omit if no agent response present. "Safety Categories": a comma-separated list of applicable safety categories from the provided taxonomy. Omit if all safe.}

              Do not include anything other than the output JSON in your response.
              Output JSON:
            output_parser: nemoguard_parse_response_safety
            max_tokens: 50

          - task: topic_safety_check_input $model=topic_control
            content: |
              You are to act as a customer service agent, providing users with factual information in accordance to the knowledge base. Your role is to ensure that you respond only to relevant queries and adhere to the following guidelines

              Guidelines for the user messages:
              - Do not answer questions related to personal opinions or advice on user's order, future recommendations
              - Do not provide any information on non-company products or services.
              - Do not answer enquiries unrelated to the company policies.
              - Do not answer questions asking for personal details about the agent or its creators.
              - Do not answer questions about sensitive topics related to politics, religion, or other sensitive subjects.
              - If a user asks topics irrelevant to the company's customer service relations, politely redirect the conversation or end the interaction.
              - Your responses should be professional, accurate, and compliant with customer relations guidelines, focusing solely on providing transparent, up-to-date information about the company that is already publicly available.
              - allow user comments that are related to small talk and chit-chat.

          - task: topic_safety_check_output $model=topic_control
            content: |
              You are to act as a customer service agent, providing users with factual information in accordance to the knowledge base. Your role is to ensure that you respond only to relevant queries and adhere to the following guidelines

              Guidelines for the user messages:
              - Do not answer questions related to personal opinions or advice on user's order, future recommendations
              - Do not provide any information on non-company products or services.
              - Do not answer enquiries unrelated to the company policies.
              - Do not answer questions asking for personal details about the agent or its creators.
              - Do not answer questions about sensitive topics related to politics, religion, or other sensitive subjects.
              - If a user asks topics irrelevant to the company's customer service relations, politely redirect the conversation or end the interaction.
              - Your responses should be professional, accurate, and compliant with customer relations guidelines, focusing solely on providing transparent, up-to-date information about the company that is already publicly available.
              - allow user comments that are related to small talk and chit-chat.

  # -- Whether to enable the OpenTelemetry exporter for the NeMo Guardrails microservice.
  otelExporterEnabled: true

  # -- Configuration for the "opentelemetry-collector" service.
  opentelemetry-collector:
    # -- Whether to enable the OpenTelemetry Collector service.
    # When enabled, an Otel collector will be deployed as a standalone service in the same namespace as Guardrails.
    enabled: true
    serviceAccount:
      # Use annotations map KSA to GSA so that the collector can write to GCP Monitoring
      annotations: {}
    # -- The configuration used by the OpenTelemetry Collector service.
    config:
      exporters:
        debug:
          verbosity: detailed
        googlecloud: {}
        googlemanagedprometheus: {}
      processors:
        # -- Detect GCP environment (project, instance/cluster), works on GKE
        resourcedetection:
          detectors: [ gcp ]
          timeout: 10s
        transform/metrics_labels:
          metric_statements:
            - context: datapoint
              statements:
                # Add convenient labels for filtering in PromQL
                - set(attributes["nemo_service_name"], resource.attributes["service.name"])
                - set(attributes["nemo_namespace"], resource.attributes["service.namespace"])
      service:
        pipelines:
          # -- The traces pipeline for the OpenTelemetry Collector service.
          traces:
            # -- The receivers for the traces pipeline for the OpenTelemetry Collector service.
            receivers: [ otlp ]
            # -- The exporters for the traces pipeline for the OpenTelemetry Collector service.
            exporters: [ debug, googlecloud ]
            # -- The processors for the traces pipeline for the OpenTelemetry Collector service.
            processors: [ batch, resourcedetection ]
          # -- The metrics pipeline for the OpenTelemetry Collector service.
          metrics:
            # -- The receivers for the metrics pipeline for the OpenTelemetry Collector service.
            receivers: [ otlp ]
            # -- The exporters for the metrics pipeline for the OpenTelemetry Collector service.
            exporters: [ debug, googlecloud, googlemanagedprometheus ]
            # -- The processors for the metrics pipeline for the OpenTelemetry Collector service.
            processors: [ resourcedetection, transform/metrics_labels, batch ]
          # -- The logs pipeline for the OpenTelemetry Collector service.
          logs:
            # -- The receivers for the logs pipeline for the OpenTelemetry Collector service.
            receivers: [ otlp ]
            # -- The exporters for the logs pipeline for the OpenTelemetry Collector service.
            exporters: [ debug, googlecloud ]
            # -- The processors for the logs pipeline for the OpenTelemetry Collector service.
            processors: [ batch, resourcedetection ]

# Disable specific MS
tags:
  # Disable Platform and install only Guardarils
  platform: false
  guardrails: true
nim-operator:
  enabled: false
nim-proxy:
  enabled: false
deployment-management:
  enabled: false
ingress:
  enabled: false
