Skip to content

Commit 2bf6bf6

Browse files
authored
build: add jsonschema library to core dependencies (#8753)
* add jsonschema to core dependencies * release note
1 parent 542a7f7 commit 2bf6bf6

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

Diff for: haystack/components/validators/json_schema.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import json
66
from typing import Any, Dict, List, Optional
77

8+
from jsonschema import ValidationError, validate
9+
810
from haystack import component
911
from haystack.dataclasses import ChatMessage
10-
from haystack.lazy_imports import LazyImport
11-
12-
with LazyImport(message="Run 'pip install jsonschema'") as jsonschema_import:
13-
from jsonschema import ValidationError, validate
1412

1513

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

Diff for: haystack/tools/tool.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
from dataclasses import asdict, dataclass
66
from typing import Any, Callable, Dict, List, Optional
77

8+
from jsonschema import Draft202012Validator
9+
from jsonschema.exceptions import SchemaError
10+
811
from haystack.core.serialization import generate_qualified_class_name, import_class_by_name
9-
from haystack.lazy_imports import LazyImport
1012
from haystack.tools.errors import ToolInvocationError
1113
from haystack.utils import deserialize_callable, serialize_callable
1214

13-
with LazyImport(message="Run 'pip install jsonschema'") as jsonschema_import:
14-
from jsonschema import Draft202012Validator
15-
from jsonschema.exceptions import SchemaError
16-
1715

1816
@dataclass
1917
class Tool:
@@ -39,7 +37,6 @@ class Tool:
3937
function: Callable
4038

4139
def __post_init__(self):
42-
jsonschema_import.check()
4340
# Check that the parameters define a valid JSON schema
4441
try:
4542
Draft202012Validator.check_schema(self.parameters)

Diff for: pyproject.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies = [
5757
"requests",
5858
"numpy",
5959
"python-dateutil",
60+
"jsonschema", # JsonSchemaValidator, Tool
6061
"haystack-experimental",
6162
]
6263

@@ -116,9 +117,6 @@ extra-dependencies = [
116117
"jsonref", # OpenAPIServiceConnector, OpenAPIServiceToFunctions
117118
"openapi3",
118119

119-
# JsonSchemaValidator, Tool
120-
"jsonschema",
121-
122120
# Tracing
123121
"opentelemetry-sdk",
124122
"ddtrace",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
enhancements:
3+
- |
4+
Add jsonschema library as a core dependency. It is used in Tool and JsonSchemaValidator.

0 commit comments

Comments
 (0)