Skip to main content

Error Handling

All SDK errors inherit from a single base class, so you can catch broad categories or specific errors as needed.

Error Hierarchy​

ScopeError (Python) / ScopeClient::Error (Ruby)
├── ConfigurationError
│ └── MissingApiKeyError
├── ApiError
│ ├── AuthenticationError
│ │ ├── TokenRefreshError
│ │ └── InvalidCredentialsError
│ ├── AuthorizationError
│ ├── NotFoundError
│ ├── ConflictError
│ ├── RateLimitError
│ └── ServerError
├── ConnectionError
│ └── TimeoutError
└── ResourceError
├── ValidationError
├── RenderError
│ └── MissingVariableError
└── NoProductionVersionError

Basic Error Handling​

from scope_client import (
ScopeClient,
ScopeError,
NotFoundError,
NoProductionVersionError,
AuthenticationError,
)

try:
version = client.get_prompt_version("my-prompt")
rendered = version.render(name="Alice")
except NoProductionVersionError as e:
print(f"No production version: {e}")
except NotFoundError as e:
print(f"Prompt not found: {e}")
except AuthenticationError as e:
print(f"Auth failed: {e}")
except ScopeError as e:
print(f"SDK error: {e}")

Handling Render Errors​

Template rendering can raise errors when variables are missing or unknown:

from scope_client import MissingVariableError, ValidationError

try:
# Missing a required variable
rendered = version.render(name="Alice")
except MissingVariableError as e:
print(f"Missing variables: {e.missing_variables}")
# e.g. ["app"]
except ValidationError as e:
print(f"Validation error: {e}")

API Error Details​

API errors include additional context for debugging:

from scope_client import ApiError

try:
version = client.get_prompt_version("my-prompt")
except ApiError as e:
print(e.message) # Human-readable message
print(e.http_status) # HTTP status code (e.g., 404)
print(e.error_code) # Machine-readable code from API
print(e.request_id) # Request ID for support

Common Errors and Solutions​

ErrorCauseSolution
ConfigurationErrorMissing credentials or API URLSet SCOPE_ORG_ID, SCOPE_API_KEY, SCOPE_API_SECRET, SCOPE_API_URL, and SCOPE_AUTH_API_URL
AuthenticationErrorInvalid or expired credentialsVerify your API key and secret are correct
NotFoundErrorPrompt name doesn't existCheck the prompt name in the Scope dashboard
NoProductionVersionErrorPrompt has no production versionPublish a version in the Scope dashboard, or use label="latest"
MissingVariableErrorTemplate has {{vars}} not providedPass all required variables to render()
RateLimitErrorToo many API requestsThe SDK retries automatically; increase retry_max_delay if needed
TimeoutErrorRequest exceeded timeoutIncrease timeout or open_timeout in client config
Was this page helpful?