Skip to content

API

Errors and Diagnostics

All PyTRIO domain exceptions inherit from pytrio.PyTrioError, carrying a stable error code, remediation hint, and request trace ID for programmatic handling and logging.

python
import pytrio

try:
    client = pytrio.ServiceClient()
    training_client = client.create_lora_training_client(base_model="Qwen/Qwen3.5-4B")
except pytrio.PyTrioError as err:
    print(err.code, err.message)
    print(err.hint)
    print(err.diagnostic_fields())

Common Exceptions ​

ExceptionModuleTypical cause
PyTrioErrorpytrio / pytrio.errors.baseBase class for all PyTRIO exceptions
ValidationErrorpytrio.errors.baseLocal input validation failure (invalid LoRA rank, empty batch, max_tokens <= 0, out-of-range token ID, checkpoint config mismatch, etc.)
DependencyErrorpytrio.errors.baseMissing optional dependency (such as torch for forward_backward_custom)
AuthErrorpytrio.errors.authMissing API key, invalid local config file, or authentication failure
ConfigurationErrorpytrio.errors.protocolInvalid profile or environment variable setting
SDKCompatibilityErrorpytrio.errors.controlCurrent SDK version is too old; upgrade pytrio

Server request and execution failures also raise subclasses of PyTrioError. Catch pytrio.PyTrioError and branch on err.code, err.status_code, and err.retryable.

Diagnostic Attributes ​

Attribute / MethodTypeDescription
messagestrUser-facing error summary
codestrStable machine-readable code (e.g., validation.invalid_lora_rank, auth.missing_api_key, billing_insufficient_balance)
hintstrSuggested fix
detailsdict[str, object]Structured error details (such as config mismatches or submission_unknown on create_batch)
status_codeintHTTP status code (0 for local errors)
retryableboolWhether the operation can be safely retried
request_idstrServer request trace ID (useful when contacting support)
diagnostic_fields()dict[str, object]Returns all non-empty diagnostic fields as a dictionary for structured logging

Error Log File ​

To persist SDK ERROR logs to a local file (defaults to ~/.pytrio/error.log), call:

python
from pytrio.logging.setup import configure_error_file_logging

configure_error_file_logging()                 # writes to ~/.pytrio/error.log
configure_error_file_logging("./pytrio.log")   # or a custom path