Enable query validation to block off-topic AI responses

Enable the question-validity shield to classify each prompt before Intelligent Assistant answers it, so that off-topic or harmful prompts never reach your answering model.

Before you begin

You have an inference provider configured and enabled in the `inference.providers` section of your `lightspeed-stack.yaml` file.

You can edit the Kubernetes Secret that supplies environment variables to the `lightspeed-core` container.

About this task

In RHDH 2.1, Intelligent Assistant validates prompts through a single question-validity shield that LCS defines in the `lightspeed-stack.yaml` configuration file. This shield replaces the Llama Guard safety provider, registered shield resources, and `run.yaml` overrides used in earlier releases. Do not edit Open GenAI Stack (OGX) files or the generated `run.yaml` file to change validation behavior.

The shipped `lightspeed-stack.yaml` file includes the shield in a disabled state. You enable or disable the shield through environment variables in the Kubernetes Secret that LCS reads. When you enable the shield, LCS sends each prompt to the validation model, which classifies the prompt as allowed or rejected.

Procedure

  1. To enable query validation, add the following keys to the Secret that LCS reads:
    stringData:
      ENABLE_VALIDATION: question_validity
      VALIDATION_PROVIDER: <provider_type>
      VALIDATION_MODEL_NAME: <model_name>
    ENABLE_VALIDATION
    Specifies whether the shield is enabled. You must set the value to `question_validity`. A nonempty value such as `true` does not enable the shield in RHDH 2.1.
    VALIDATION_PROVIDER
    Specifies the type of the inference provider that runs the classification, for example, `openai` or `vllm`. A provider of this type must be enabled in `inference.providers`.
    VALIDATION_MODEL_NAME
    Specifies the model that classifies each prompt. If the provider defines `allowed_models`, include this model in that list.

    For example, to run classification on an `openai` provider with the `gpt-4o-mini` model, set the following values:

    stringData:
      ENABLE_VALIDATION: question_validity
      VALIDATION_PROVIDER: openai
      VALIDATION_MODEL_NAME: gpt-4o-mini
  2. To keep query validation disabled, leave `ENABLE_VALIDATION` unset, or set it to `__disabled__`:
    stringData:
      ENABLE_VALIDATION: __disabled__
    Note
    Running without query validation increases the risk of off-topic or harmful model output. Disable validation only in secure development environments.
  3. Apply the updated Secret, and then restart the LCS service so that the container reads the new environment variables.

What to do next

  • Open the *Intelligent Assistant* and submit a development question, for example, `How do I create a software template in RHDH?`. Confirm that the assistant answers the question.
  • Submit a clearly unrelated question, for example, `What is a good recipe for pizza?`. Confirm that the assistant rejects the question when validation is enabled.