Creates a guardrail that restricts input to specific topics using allowlist or denylist regex patterns.
Arguments
- allowed_topics
Character vector of regex patterns. If non-
NULL, input must match at least one pattern to pass. Cannot be used together withdenied_topics.- denied_topics
Character vector of regex patterns. Input must not match any of these patterns. Cannot be used together with
allowed_topics.- case_sensitive
Logical(1). Whether pattern matching is case-sensitive. Default:
FALSE.
Examples
g <- guard_topic_scope(allowed_topics = c("statistics", "data analysis"))
run_guardrail(g, "How do I calculate a t-test in statistics?")
#> <guardrail_result> PASS
run_guardrail(g, "What is the weather today?")
#> <guardrail_result> FAIL
#> Reason: Input does not match any allowed topic.