Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust
1.0 KB
Raw Blame
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! Error mapping for the Python bindings.

use pyo3::create_exception;
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;

create_exception!(_switchyard_rust, LibsyError, PyRuntimeError);
create_exception!(_switchyard_rust, ContextWindowExceededError, PyRuntimeError);
create_exception!(_switchyard_rust, ServerConfigError, PyRuntimeError);

/// Converts libsy execution failures into one stable Python exception.
pub(crate) fn py_libsy_error(error: impl std::fmt::Display) -> PyErr {
    LibsyError::new_err(error.to_string())
}

pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
    module.add("LibsyError", module.py().get_type::<LibsyError>())?;
    module.add(
        "ContextWindowExceededError",
        module.py().get_type::<ContextWindowExceededError>(),
    )?;
    module.add(
        "ServerConfigError",
        module.py().get_type::<ServerConfigError>(),
    )
}