Skip to main content
Generated from promptguard-sdk 2.4.2 as published on PyPI (sha256 0fae2f792594…). Signatures, parameters and descriptions are read from the package itself, so this page changes only when the pinned SDK version does. For a walkthrough, start with the guide.

promptguard

PromptGuard Python SDK

Config

Class · from promptguard import Config
Configuration for the proxy PromptGuard client.
Fields
  • api_key: str = field(repr=False)
  • base_url: str = 'https://api.promptguard.co/api/v1/proxy'
  • max_retries: int = 3
  • retry_delay: float = 1.0
  • timeout: float = 30.0

GuardApiError

Class · from promptguard import GuardApiError
Raised when the Guard API is unreachable or returns an error.

GuardApiError(...)

GuardClient

Class · from promptguard import GuardClient
HTTP client for the PromptGuard Guard API.

GuardClient(...)

GuardClient.scan

Synchronous scan via the guard API.

GuardClient.scan_async

Asynchronous scan via the guard API.

GuardClient.close

Close the sync client and best-effort close all async clients.

GuardClient.aclose

Async close: awaits the current loop’s client, best-effort for others.

GuardDecision

Class · from promptguard import GuardDecision
Result of a guard API call. Properties
  • blocked: bool
  • redacted: bool
  • allowed: bool

GuardDecision(...)

PromptGuard

Class · from promptguard import PromptGuard
PromptGuard client - Drop-in security for AI applications.

PromptGuard(...)

PromptGuard.close

PromptGuard.chat

Reached as PromptGuard.chat on an instance (a Chat; not constructed directly).

PromptGuard.chat.completions

Reached as PromptGuard.chat.completions on an instance (a ChatCompletions; not constructed directly).

PromptGuard.chat.completions.create

PromptGuard.security

Reached as PromptGuard.security on an instance (a Security; not constructed directly).

PromptGuard.security.scan

PromptGuard.security.redact

PromptGuard.agent

Reached as PromptGuard.agent on an instance (a Agent; not constructed directly).

PromptGuard.agent.validate_tool

PromptGuard.agent.stats

PromptGuard.redteam

Reached as PromptGuard.redteam on an instance (a RedTeam; not constructed directly).
Run the adversarial corpus against your own policy configuration.

PromptGuard.redteam.list_tests

PromptGuard.redteam.run_test

PromptGuard.redteam.run_all

PromptGuard.redteam.run_custom

PromptGuardAsync

Class · from promptguard import PromptGuardAsync
Async PromptGuard client — full parity with the sync client.

PromptGuardAsync(...)

PromptGuardAsync.close

PromptGuardAsync.chat

Reached as PromptGuardAsync.chat on an instance (a AsyncChat; not constructed directly).

PromptGuardAsync.chat.completions

Reached as PromptGuardAsync.chat.completions on an instance (a AsyncChatCompletions; not constructed directly).

PromptGuardAsync.chat.completions.create

PromptGuardAsync.security

Reached as PromptGuardAsync.security on an instance (a AsyncSecurity; not constructed directly).

PromptGuardAsync.security.scan

PromptGuardAsync.security.redact

PromptGuardAsync.agent

Reached as PromptGuardAsync.agent on an instance (a AsyncAgent; not constructed directly).

PromptGuardAsync.agent.validate_tool

PromptGuardAsync.agent.stats

PromptGuardAsync.redteam

Reached as PromptGuardAsync.redteam on an instance (a AsyncRedTeam; not constructed directly).
Async counterpart of :class:RedTeam; see it for why the paths moved and why run_autonomous / intelligence_stats are gone.

PromptGuardAsync.redteam.list_tests

PromptGuardAsync.redteam.run_test

PromptGuardAsync.redteam.run_all

PromptGuardAsync.redteam.run_custom

PromptGuardBlockedError

Class · from promptguard import PromptGuardBlockedError
Raised when PromptGuard blocks a request in enforce mode.

PromptGuardBlockedError(...)

PromptGuardError

Class · from promptguard import PromptGuardError
Error from PromptGuard API

PromptGuardError(...)

SecurityScanResult

Class · from promptguard import SecurityScanResult
Result of a security.scan call.
Fields
  • blocked: bool
  • decision: str
  • reason: str
  • threat_type: str
  • confidence: float

__version__

Constant · from promptguard import __version__

init

Function · from promptguard import init
Initialise PromptGuard auto-instrumentation.

instrumentation_report

Function · from promptguard import instrumentation_report
What is and is not instrumented, as data rather than a log line.

is_active

Function · from promptguard import is_active
Return True when auto-instrumentation is initialised (a guard client is installed). Note this is independent of whether any SDK was patchable — use :func:patched_sdks to confirm specific SDKs are instrumented.

patched_sdks

Function · from promptguard import patched_sdks
Return the names of the SDKs actually patched by the last init().

shutdown

Function · from promptguard import shutdown
Remove all patches and close the guard client.

verify

Function · from promptguard import verify
Run the integration checks and return what happened.

promptguard.integrations.langchain

LangChain integration - PromptGuardCallbackHandler.

LangChainCallbackHandler

Alias · from promptguard.integrations.langchain import LangChainCallbackHandler
Alias of PromptGuardCallbackHandler.

PromptGuardCallbackHandler

Class · from promptguard.integrations.langchain import PromptGuardCallbackHandler
LangChain callback handler that scans LLM I/O via the Guard API.

PromptGuardCallbackHandler(...)

Construct the handler.

PromptGuardCallbackHandler.on_llm_start

PromptGuardCallbackHandler.on_chat_model_start

PromptGuardCallbackHandler.on_llm_end

PromptGuardCallbackHandler.on_llm_error

PromptGuardCallbackHandler.on_chain_start

PromptGuardCallbackHandler.on_chain_end

PromptGuardCallbackHandler.on_chain_error

PromptGuardCallbackHandler.on_tool_start

PromptGuardCallbackHandler.on_tool_end

PromptGuardCallbackHandler.on_tool_error

PromptGuardRunnable

Class · from promptguard.integrations.langchain import PromptGuardRunnable
Inline LCEL guard that scans (and can redact) content mid-chain.

PromptGuardRunnable(...)

PromptGuardRunnable.guard_value

Scan value; return it (possibly redacted) or raise on a block.

PromptGuardRunnable.as_runnable

Wrap :meth:guard_value in a langchain_core RunnableLambda.

promptguard.integrations.llamaindex

LlamaIndex integration - PromptGuardCallbackHandler for LlamaIndex.

LlamaIndexCallbackHandler

Alias · from promptguard.integrations.llamaindex import LlamaIndexCallbackHandler
Alias of PromptGuardCallbackHandler.

PromptGuardCallbackHandler

Class · from promptguard.integrations.llamaindex import PromptGuardCallbackHandler
LlamaIndex callback handler that scans LLM I/O via the Guard API.

PromptGuardCallbackHandler(...)

Construct the handler.

PromptGuardCallbackHandler.on_event_start

PromptGuardCallbackHandler.on_event_end

PromptGuardCallbackHandler.start_trace

PromptGuardCallbackHandler.end_trace

PromptGuardQueryGuard

Class · from promptguard.integrations.llamaindex import PromptGuardQueryGuard
Inline LlamaIndex guard that scans (and can redact) a query string.

PromptGuardQueryGuard(...)

PromptGuardQueryGuard.guard_query

Scan query_str; return it (possibly redacted) or raise on a block.

PromptGuardQueryGuard.as_query_component

Wrap :meth:guard_query in a LlamaIndex FnComponent.

promptguard.integrations.crewai

CrewAI integration - guardrail function and tool wrapper.

PromptGuardGuardrail

Class · from promptguard.integrations.crewai import PromptGuardGuardrail
CrewAI guardrail that scans inputs/outputs via the Guard API.

PromptGuardGuardrail(...)

session_id names the Conversation the crew’s scans belong to. CrewAI has no conversation id of its own, so without one none is sent.

PromptGuardGuardrail.before_kickoff

Scan crew inputs before kickoff.

PromptGuardGuardrail.after_kickoff

Scan crew output after kickoff.

PromptGuardGuardrail.scan_task_output

Scan an individual task’s output.

secure_tool

Function · from promptguard.integrations.crewai import secure_tool
Decorator to wrap a CrewAI tool’s _run method with PromptGuard.

promptguard.integrations.fastapi

ASGI middleware - scans prompt-shaped request bodies at the app’s edge.

extract_scan

Function · from promptguard.integrations.fastapi import extract_scan
What to scan in a parsed body (an object, or a top-level array).

PromptGuardMiddleware

Class · from promptguard.integrations.fastapi import PromptGuardMiddleware
Raw ASGI middleware that scans prompt-shaped request bodies.

PromptGuardMiddleware(...)

Last modified on October 31, 2026