Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support recursive references in json schema #98

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ repository = "https://github.com/dottxt-ai/outlines-core"

[dependencies]
once_cell = "1.20"
anyhow = "1.0.86"
thiserror = "2.0"
pyo3 = { version = "0.22.0", features = ["extension-module"], optional = true }
regex = "1.10.6"
Expand Down
51 changes: 51 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,57 @@ pub enum Error {
ByteFallbackProcessorFailed,
}

// TODO: Integrate JsonSchema errors and simplify
#[derive(Error, Debug)]
pub enum JsonSchemaParserError {
#[error("serde json error")]
SerdeJsonError(#[from] serde_json::Error),
#[error("Unsupported JSON Schema structure {0} \nMake sure it is valid to the JSON Schema specification and check if it's supported by Outlines.\nIf it should be supported, please open an issue.")]
UnsupportedJsonSchema(Box<serde_json::Value>),
#[error("'properties' not found or not an object")]
PropertiesNotFound,
#[error("'allOf' must be an array")]
AllOfMustBeAnArray,
#[error("'anyOf' must be an array")]
AnyOfMustBeAnArray,
#[error("'oneOf' must be an array")]
OneOfMustBeAnArray,
#[error("'prefixItems' must be an array")]
PrefixItemsMustBeAnArray,
#[error("Unsupported data type in enum: {0}")]
UnsupportedEnumDataType(Box<serde_json::Value>),
#[error("'enum' must be an array")]
EnumMustBeAnArray,
#[error("Unsupported data type in const: {0}")]
UnsupportedConstDataType(Box<serde_json::Value>),
#[error("'const' key not found in object")]
ConstKeyNotFound,
#[error("'$ref' must be a string")]
RefMustBeAString,
#[error("External references are not supported: {0}")]
ExternalReferencesNotSupported(Box<str>),
#[error("Invalid reference format: {0}")]
InvalidReferenceFormat(Box<str>),
#[error("'type' must be a string")]
TypeMustBeAString,
#[error("Unsupported type: {0}")]
UnsupportedType(Box<str>),
#[error("maxLength must be greater than or equal to minLength")]
MaxBoundError,
#[error("Format {0} is not supported by Outlines")]
StringTypeUnsupportedFormat(Box<str>),
#[error("Invalid reference path: {0}")]
InvalidRefecencePath(Box<str>),
#[error("Ref recusion limit reached: {0}")]
RefRecursionLimitReached(usize),
}

impl JsonSchemaParserError {
pub fn is_recursion_limit(&self) -> bool {
matches!(self, Self::RefRecursionLimitReached(_))
}
}

#[cfg(feature = "python-bindings")]
impl From<Error> for pyo3::PyErr {
fn from(e: Error) -> Self {
Expand Down
40 changes: 0 additions & 40 deletions src/json_schema/helpers.rs

This file was deleted.

Loading
Loading