Callback handler
PromptGuardCallbackHandler from promptguard.integrations.llamaindex joins LlamaIndex’s callback manager. It scans the prompt at the start of every llm event and the query string at the start of every query event, and, unless you pass scan_responses=False, the response at the end of each.
PromptGuardBlockedError, rather than let content through that should have been redacted. To redact a query, use the query guard below. To skip events, pass their types in event_starts_to_ignore or event_ends_to_ignore.
If you also use the LangChain handler, LlamaIndexCallbackHandler is the same class under a name that does not clash.
Query guard
PromptGuardQueryGuard.guard_query() scans a query string before you hand it to an index, and returns it redacted when the decision is redact, in enforce mode. On a block it raises PromptGuardBlockedError.
Auto-instrumentation
LlamaIndex’s LLM classes call the provider SDKs underneath, so auto-instrumentation scans calls made through the patched SDKs, such asllama-index-llms-openai, which uses the openai package. It sees each model call, not LlamaIndex’s queries; use the handler for those.