Skip to main content

Guardrails

Every SDK-routed request and response is scanned locally for built-in PII and credential patterns. Matches are recorded on spans as guardrail attributes; normal SDK traffic is never blocked or rewritten.

SDK behaviour​

The transport uses scan-and-record behaviour:

  • Prompt and response continue unchanged.
  • Match names are recorded as guardrail.violation.
  • guardrail.action is recorded as warn.
  • A guardrail or telemetry failure never prevents the provider call.

This is intentional. Observra's gateway and provider call remain authoritative for request success or failure.

Built-in patterns​

NameMatches
emailEmail addresses
credit_cardDigit sequences shaped like payment cards
ssnUS Social Security numbers such as 123-45-6789
phoneCommon US and international phone-number formats
api_keyLong sk-... keys
generic_tokenLong obs, ghp, gho, or xox tokens

Patterns are regular expressions. False positives are possible; treat matches as observability and safety signals, not compliance enforcement.

Bounded scanning​

Only the first 50,000 characters of a payload are scanned. Remaining content continues unchanged and unscanned. This bounds local work for unusually large prompts and responses.

Direct checker​

Advanced code can use the internal checker directly for warn, redact, or block decisions. This module is not part of the stable top-level public API, so pin and test against your SDK version if you depend on it.

from observra.guardrails.check import GuardrailViolation, check_payload

try:
result = check_payload("My SSN is 123-45-6789.", mode="block")
except GuardrailViolation as error:
print([violation.pattern_name for violation in error.violations])

Modes:

  • warn: return violations and leave payload unchanged.
  • redact: return a result whose redacted_payload masks matches.
  • block: raise GuardrailViolation when any match exists.

Direct checker modes do not change the SDK transport's scan-and-record policy.

Next​