## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = TRUE)

## -----------------------------------------------------------------------------
library(llmshieldr)

## -----------------------------------------------------------------------------
policy(
  "comprehensive",
  overrides = list(thresholds = list(redact_at = 0.3, block_at = 0.6))
)

## -----------------------------------------------------------------------------
scan_prompt(
  "Contact neel@example.com.",
  redaction = redaction_strategy("mask")
)

scan_prompt(
  "Contact neel@example.com.",
  redaction = redaction_strategy("hash")
)

## -----------------------------------------------------------------------------
scanners <- scanner_options(
  max_tokens = 500,
  blocked_topics = c("unreleased earnings"),
  allowed_url_hosts = c("example.com", "docs.example.com")
)

scan_prompt(
  "Email neel@example.com about unreleased earnings.",
  scanners = scanners
)

## -----------------------------------------------------------------------------
controlled <- policy(
  "enterprise_default",
  overrides = list(
    controls = policy_controls(
      on_prompt_block = "refuse",
      on_context_block = "drop",
      on_output_block = "escalate",
      refusal_message = "Please rephrase the request."
    )
  )
)

## -----------------------------------------------------------------------------
guardrails <- policy()

guardrails <- add_rule(
  guardrails,
  id = "llm02.ticket_id",
  pattern = "\\bTICKET-[0-9]{6}\\b",
  owasp = "llm02",
  severity = "medium",
  action = "redact",
  description = "Internal support ticket identifier."
)

list_rules(guardrails)

