AWSTemplateFormatVersion: "2010-09-09"
Description: >-
  cloud path, AIF-C01 lab 7. Guardrail de Amazon Bedrock para un chatbot de banco:
  un tema denegado (consejos de inversion), filtros de contenido en nivel alto,
  ataque de prompt en la entrada y PII enmascarada. El guardrail no cuesta mientras
  no se use; cada evaluacion se cobra por unidad de texto (ver labs.md).
  Nivel Classic: admite espanol y no exige inferencia entre regiones.

Parameters:
  NombreGuardrail:
    Type: String
    Default: cloudpath-lab7-banco
    AllowedPattern: "^[0-9a-zA-Z-_]+$"
    Description: Nombre del guardrail (letras, numeros, guiones).

Resources:
  GuardrailBanco:
    Type: AWS::Bedrock::Guardrail
    Properties:
      Name: !Ref NombreGuardrail
      Description: Lab 7 de AIF-C01 en cloud path. Chatbot de atencion a clientes de un banco.
      BlockedInputMessaging: >-
        No puedo ayudarte con eso. Puedo responder preguntas sobre tus cuentas,
        tarjetas y pagos.
      BlockedOutputsMessaging: >-
        No puedo darte esa respuesta. Puedo responder preguntas sobre tus cuentas,
        tarjetas y pagos.
      TopicPolicyConfig:
        TopicsTierConfig:
          TierName: CLASSIC
        TopicsConfig:
          - Name: Consejos de inversion
            Type: DENY
            Definition: >-
              Recomendaciones o guia sobre en que invertir dinero o activos para obtener
              rendimientos, incluidas acciones, fondos y criptomonedas.
            Examples:
              - En que acciones me conviene invertir este ano?
              - Me recomiendas comprar bitcoin?
              - Que fondo de inversion me da mas rendimiento?
      ContentPolicyConfig:
        ContentFiltersTierConfig:
          TierName: CLASSIC
        FiltersConfig:
          - Type: HATE
            InputStrength: HIGH
            OutputStrength: HIGH
          - Type: INSULTS
            InputStrength: HIGH
            OutputStrength: HIGH
          - Type: SEXUAL
            InputStrength: HIGH
            OutputStrength: HIGH
          - Type: VIOLENCE
            InputStrength: HIGH
            OutputStrength: HIGH
          - Type: MISCONDUCT
            InputStrength: HIGH
            OutputStrength: HIGH
          - Type: PROMPT_ATTACK
            InputStrength: HIGH
            OutputStrength: NONE
      SensitiveInformationPolicyConfig:
        PiiEntitiesConfig:
          - Type: NAME
            Action: ANONYMIZE
          - Type: EMAIL
            Action: ANONYMIZE
          - Type: PHONE
            Action: ANONYMIZE
          - Type: CREDIT_DEBIT_CARD_NUMBER
            Action: BLOCK
        RegexesConfig:
          - Name: numero-de-cliente
            Description: Numero de cliente ficticio del lab, por ejemplo CLI-12345678.
            Pattern: "CLI-[0-9]{8}"
            Action: ANONYMIZE
      Tags:
        - Key: curso
          Value: cloudpath-aif-c01-lab7

  VersionGuardrail:
    Type: AWS::Bedrock::GuardrailVersion
    Properties:
      GuardrailIdentifier: !GetAtt GuardrailBanco.GuardrailId
      Description: Version 1 del lab 7

Outputs:
  GuardrailId:
    Description: ID del guardrail (se usa al invocar un modelo).
    Value: !GetAtt GuardrailBanco.GuardrailId
  GuardrailVersion:
    Description: Version publicada del guardrail.
    Value: !GetAtt VersionGuardrail.Version
