Error Handling

Foundry uses structured error classes that provide clear context for both humans and AI agents.

Error Structure

All Foundry errors include:

class FoundryError(Exception):
    code: str           # Machine-readable error code
    message: str        # Human-readable message
    details: dict       # Additional context
    recovery_hint: str  # How to fix the issue

Error Types

DatasetNotFoundError

Raised when a search or get operation returns no results.

from foundry.errors import DatasetNotFoundError

try:
    dataset = f.get_dataset("nonexistent-doi")
except DatasetNotFoundError as e:
    print(e.code)           # "DATASET_NOT_FOUND"
    print(e.message)        # "No dataset found matching..."
    print(e.recovery_hint)  # "Try a broader search term..."

AuthenticationError

Raised when authentication fails.

DownloadError

Raised when a file download fails.

DataLoadError

Raised when data files cannot be parsed.

ValidationError

Raised when metadata validation fails.

PublishError

Raised when dataset publication fails.

CacheError

Raised when local cache operations fail.

ConfigurationError

Raised when configuration is invalid.

Error Codes Reference

Code
Error Class
Common Causes

DATASET_NOT_FOUND

DatasetNotFoundError

Invalid DOI, no search results

AUTH_FAILED

AuthenticationError

Expired token, no credentials

DOWNLOAD_FAILED

DownloadError

Network issues, URL not found

DATA_LOAD_FAILED

DataLoadError

Corrupted file, wrong format

VALIDATION_FAILED

ValidationError

Missing required fields

PUBLISH_FAILED

PublishError

Server error, permission denied

CACHE_ERROR

CacheError

Disk full, permission denied

CONFIG_ERROR

ConfigurationError

Invalid parameter values

Handling Errors

Basic Pattern

Catch All Foundry Errors

Serialization for APIs

Errors can be serialized for JSON responses:

For AI Agents

Structured errors are designed for programmatic handling:

The recovery_hint field is particularly useful for agents to suggest next steps to users.

Custom Error Handling

Retry Logic

Fallback Strategies

Last updated

Was this helpful?