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

build: add jsonschema library to core dependencies #8753

Merged
merged 2 commits into from
Jan 21, 2025
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
7 changes: 2 additions & 5 deletions haystack/components/validators/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import json
from typing import Any, Dict, List, Optional

from jsonschema import ValidationError, validate

from haystack import component
from haystack.dataclasses import ChatMessage
from haystack.lazy_imports import LazyImport

with LazyImport(message="Run 'pip install jsonschema'") as jsonschema_import:
from jsonschema import ValidationError, validate


def is_valid_json(s: str) -> bool:
Expand Down Expand Up @@ -110,7 +108,6 @@ def __init__(self, json_schema: Optional[Dict[str, Any]] = None, error_template:
the messages' content is validated.
:param error_template: A custom template string for formatting the error message in case of validation failure.
"""
jsonschema_import.check()
self.json_schema = json_schema
self.error_template = error_template

Expand Down
9 changes: 3 additions & 6 deletions haystack/tools/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
from dataclasses import asdict, dataclass
from typing import Any, Callable, Dict, List, Optional

from jsonschema import Draft202012Validator
from jsonschema.exceptions import SchemaError

from haystack.core.serialization import generate_qualified_class_name, import_class_by_name
from haystack.lazy_imports import LazyImport
from haystack.tools.errors import ToolInvocationError
from haystack.utils import deserialize_callable, serialize_callable

with LazyImport(message="Run 'pip install jsonschema'") as jsonschema_import:
from jsonschema import Draft202012Validator
from jsonschema.exceptions import SchemaError


@dataclass
class Tool:
Expand All @@ -39,7 +37,6 @@ class Tool:
function: Callable

def __post_init__(self):
jsonschema_import.check()
# Check that the parameters define a valid JSON schema
try:
Draft202012Validator.check_schema(self.parameters)
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies = [
"requests",
"numpy",
"python-dateutil",
"jsonschema", # JsonSchemaValidator, Tool
"haystack-experimental",
]

Expand Down Expand Up @@ -116,9 +117,6 @@ extra-dependencies = [
"jsonref", # OpenAPIServiceConnector, OpenAPIServiceToFunctions
"openapi3",

# JsonSchemaValidator, Tool
"jsonschema",

# Tracing
"opentelemetry-sdk",
"ddtrace",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
enhancements:
- |
Add jsonschema library as a core dependency. It is used in Tool and JsonSchemaValidator.
Loading