가드레일 구성

OCIAIConf()를 사용하여 기본 모델을 선택하는 과정에서 보조 장치를 사용하여 보호대를 구성할 수 있습니다.

OCI Generative AI 서비스에서 기본 모델을 선택할 때 Guardrails 구성이 제공됩니다. 이 예에서는 xai.grok-4 모델을 선택합니다.

from aidputils.agents.toolkit.configs import OCIAIConf 
guardrails_config = { 
    "name" : "<guardrailsName>", 
    "description" : "<guardrailsDescription>", 
    "policies" : [ ] 
  } 
model_args = {} 
llm_conf = OCIAIConf(model_provider='generic', 
                     compartment_id='<compartment_ocid>', 
                     model_args=model_args, 
                     endpoint='https://inference.generativeai.<oci-region>.oci.oraclecloud.com', 
                     model_id='xai.grok-4', 
                     guardrails_config=guardrails_config)

가드레일 구성은 정책 배열로 구성된 JSON과 유사한 문자열입니다. 위 예제에서는 이 코드 블록에서 정의됩니다. 여기서 <guardrailsName><guardrailsDescription>는 유저 정의 이름과 설명입니다.


guardrails_config = { 
    "name" : "<guardrailsName>", 
    "description" : "<guardrailsDescription>", 
    "policies" : [ ] 
  }

각 정책에는 다음 키가 있습니다.

핵심 필수사항 설명 데이터 유형 기본값
policyName 아니요 정책의 사용자정의 이름 String N/A
policyType 적용할 난간 정책의 유형입니다.
허용되는 값은 다음과 같습니다.
  • CONTENT_MODERATION
  • PROMPT_ATTACKS_PREVENTION
  • PII_DETECTION
열거  
policyDescription 아니요 정책에 대한 설명 String  
scope 아니요 범위는 가드레일이 적용되는 위치를 정의합니다.
허용되는 값은 다음과 같습니다.
  • USER_REQUEST
  • AGENT_RESPONSE
  • BOTH
열거  
action 아니요 정책 위반 시 수행할 작업입니다.
허용되는 값은 다음과 같습니다.
  • INFORM
  • BLOCK
  • ALLOW MASK

    (PII_DETECTION에만 해당)

열거  
threshold 아니요 감지에 대한 임계값입니다.

범위는 0과 1 사이의 확률입니다.

float  
piiCategories 해당 작업 및 사용으로 설정과 함께 감지될 PII 데이터의 범주입니다. Array  

piiCategories는 다음 키를 사용하는 JSON과 유사한 객체의 배열이기도 합니다.

핵심 필수사항 설명 데이터 유형 기본값
category 감지할 PII 범주입니다.
허용되는 값은 다음과 같습니다.
  • PERSON
  • ADDRESS
  • TELEPHONE_NUMBER
  • EMAIL
String N/A
isEnabled 아니요 PII 범주의 감지를 사용으로 설정합니다.
허용되는 값은 다음과 같습니다.
  • True
  • False
열거  
action 아니요 PII 범주가 감지된 경우 수행할 작업입니다. 위의 작업을 무효화합니다.
허용되는 값은 다음과 같습니다.
  • INFORM
  • BLOCK
  • ALLOW
  • MASK
String  

예: Complete Guardrails 구성

이 경우 세 가지 정책을 모두 적용합니다.
  • 콘텐츠 조정은 에이전트 응답에만 적용됩니다.
  • 프롬프트 삽입은 감지된 경우 사용자 요청을 차단합니다.
  • PII가 에이전트 응답과 사용자 요청 모두에서 감지되었습니다. 각 PII 범주는 다르게 처리됩니다.
guardrails_config = { 
    "policies" : [ { 
      "policyType" : "CONTENT_MODERATION", 
      "policyName" : "Content Moderation prevention", 
      "policyDescription" : "Choose an action to take when hate, sexual, violence, toxic, derogatory, or harassment content is detected in either the user input query or the agent response.", 
      "scope" : "AGENT_RESPONSE", 
      "action" : "INFORM", 
      "threshold" : 0.5, 
      "categories" : [ ] 
    }, { 
      "policyType" : "PROMPT_ATTACKS_PREVENTION", 
      "policyName" : "Prompt Injection prevention", 
      "policyDescription" : "Choose action when prompt injection is detected on the user query.", 
      "scope" : "USER_REQUEST", 
      "action" : "BLOCK", 
      "threshold" : 0.5 
    }, { 
      "policyType" : "PII_DETECTION", 
      "policyName" : "Personally Identifiable Information (PII) detection", 
      "policyDescription" : "Choose an action to take when PII entities are detected in either the user input query or the agent response.", 
      "scope" : "AGENT_RESPONSE", 
      "action" : "INFORM", 
      "threshold" : 0.5, 
      "piiCategories" : [ { 
        "category" : "PERSON", 
        "isEnabled" : False, 
        "action" : "INFORM" 
      }, { 
        "category" : "ADDRESS", 
        "isEnabled" : False, 
        "action" : "INFORM" 
      }, { 
        "category" : "TELEPHONE_NUMBER", 
        "isEnabled" : True, 
        "action" : "MASK" 
      }, { 
        "category" : "EMAIL", 
        "isEnabled" : True, 
        "action" : "MASK" 
      } ] 
    }, { 
      "policyType" : "PII_DETECTION", 
      "policyName" : "Personally Identifiable Information (PII) detection", 
      "policyDescription" : "Choose an action to take when PII entities are detected in either the user input query or the agent response.", 
      "scope" : "USER_REQUEST", 
      "action" : "INFORM", 
      "threshold" : 0.5, 
      "piiCategories" : [ { 
        "category" : "PERSON", 
        "isEnabled" : True, 
        "action" : "INFORM" 
      }, { 
        "category" : "ADDRESS", 
        "isEnabled" : True, 
        "action" : "INFORM" 
      }, { 
        "category" : "TELEPHONE_NUMBER", 
        "isEnabled" : True, 
        "action" : "BLOCK" 
      }, { 
        "category" : "EMAIL", 
        "isEnabled" : False, 
        "action" : "INFORM" 
      } ] 
    } ] 
  }