From 93090e3b08894faa00eca39a8a625473df82e01e Mon Sep 17 00:00:00 2001 From: anakin87 Date: Mon, 20 Jan 2025 18:57:41 +0100 Subject: [PATCH 1/2] add jsonschema to core dependencies --- haystack/components/validators/json_schema.py | 7 ++----- haystack/tools/tool.py | 9 +++------ pyproject.toml | 4 +--- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/haystack/components/validators/json_schema.py b/haystack/components/validators/json_schema.py index 0a449aff42..051773113c 100644 --- a/haystack/components/validators/json_schema.py +++ b/haystack/components/validators/json_schema.py @@ -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: @@ -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 diff --git a/haystack/tools/tool.py b/haystack/tools/tool.py index bdb8f005b6..fd4802879f 100644 --- a/haystack/tools/tool.py +++ b/haystack/tools/tool.py @@ -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: @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 258e4e2710..481f3546d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ dependencies = [ "requests", "numpy", "python-dateutil", + "jsonschema", # JsonSchemaValidator, Tool "haystack-experimental", ] @@ -116,9 +117,6 @@ extra-dependencies = [ "jsonref", # OpenAPIServiceConnector, OpenAPIServiceToFunctions "openapi3", - # JsonSchemaValidator, Tool - "jsonschema", - # Tracing "opentelemetry-sdk", "ddtrace", From 0ca872a4aecf02ab13d3bb496f457894c82c3f08 Mon Sep 17 00:00:00 2001 From: anakin87 Date: Mon, 20 Jan 2025 18:59:54 +0100 Subject: [PATCH 2/2] release note --- .../notes/jsonschema-core-dependency-d38645d819eb0d2d.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releasenotes/notes/jsonschema-core-dependency-d38645d819eb0d2d.yaml diff --git a/releasenotes/notes/jsonschema-core-dependency-d38645d819eb0d2d.yaml b/releasenotes/notes/jsonschema-core-dependency-d38645d819eb0d2d.yaml new file mode 100644 index 0000000000..f8579ebcdd --- /dev/null +++ b/releasenotes/notes/jsonschema-core-dependency-d38645d819eb0d2d.yaml @@ -0,0 +1,4 @@ +--- +enhancements: + - | + Add jsonschema library as a core dependency. It is used in Tool and JsonSchemaValidator.