Skip to content

Commit 2a73529

Browse files
fix: enhance package typing, logging, and schema evaluation (#28)
1 parent e0b1ed4 commit 2a73529

5 files changed

Lines changed: 38 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ readme = "README.md"
1010
license = "BSD-3-Clause"
1111
authors = [{ name = "evalwire contributors" }]
1212
requires-python = ">=3.10"
13+
keywords = ["evaluation", "langgraph", "phoenix", "llm", "testing", "arize"]
14+
classifiers = [
15+
"Development Status :: 4 - Beta",
16+
"Intended Audience :: Developers",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
21+
"Programming Language :: Python :: 3.13",
22+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
23+
"Topic :: Software Development :: Testing",
24+
"Typing :: Typed",
25+
]
1326
dependencies = [
1427
"arize-phoenix>=13.0,<14",
1528
"pandas>=2.0",

src/evalwire/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""evalwire — systematic evaluation of LangGraph nodes with Arize Phoenix."""
22

3+
import logging
4+
from importlib.metadata import version
5+
36
from evalwire.evaluators import (
47
make_contains_evaluator,
58
make_exact_match_evaluator,
@@ -15,6 +18,10 @@
1518
from evalwire.runner import ExperimentRunner
1619
from evalwire.uploader import DatasetUploader
1720

21+
__version__ = version("evalwire")
22+
23+
logging.getLogger("evalwire").addHandler(logging.NullHandler())
24+
1825
__all__ = [
1926
"DatasetUploader",
2027
"ExperimentRunner",

src/evalwire/evaluators/membership.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def make_membership_evaluator() -> Callable[[str, dict], bool]:
2222
"""
2323

2424
def is_in(output: str, expected: dict) -> bool:
25+
if output is None:
26+
return False
2527
expected_items = _parse_expected(expected)
2628
return output in expected_items
2729

src/evalwire/evaluators/schema.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ def make_schema_evaluator(schema: dict) -> Callable[[str, dict], bool]:
1111
Schema dict using ``jsonschema``. Useful for asserting that LLM outputs
1212
conform to a declared schema regardless of the specific values produced.
1313
14-
The JSON schema is bound at factory-creation time so the same validator
15-
can be reused across many evaluation rows without re-compiling.
14+
The JSON schema and validator are both bound at factory-creation time so
15+
the same validator can be reused across many evaluation rows without
16+
re-compiling or re-importing.
1617
1718
Parameters
1819
----------
@@ -37,27 +38,24 @@ def make_schema_evaluator(schema: dict) -> Callable[[str, dict], bool]:
3738
3839
pip install 'jsonschema>=4.0'
3940
"""
41+
try:
42+
import jsonschema
43+
except ImportError as exc:
44+
raise ImportError(
45+
"jsonschema is required to use make_schema_evaluator. "
46+
"Install it with: pip install 'jsonschema>=4.0'"
47+
) from exc
48+
49+
validator = jsonschema.Draft7Validator(schema)
4050

4151
def schema_valid(output: str, expected: dict) -> bool: # noqa: ARG001
4252
if output is None:
4353
return False
44-
try:
45-
import jsonschema
46-
except ImportError as exc:
47-
raise ImportError(
48-
"jsonschema is required to use make_schema_evaluator. "
49-
"Install it with: pip install 'jsonschema>=4.0'"
50-
) from exc
51-
5254
try:
5355
instance = json.loads(output)
5456
except (json.JSONDecodeError, TypeError):
5557
return False
56-
try:
57-
jsonschema.validate(instance=instance, schema=schema)
58-
except jsonschema.ValidationError:
59-
return False
60-
return True
58+
return validator.is_valid(instance)
6159

6260
schema_valid.__name__ = "schema_valid"
6361
return schema_valid

tests/test_evaluators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,11 @@ def test_expected_dict_is_ignored(self):
496496
def test_jsonschema_absent_raises_import_error(
497497
self, monkeypatch: pytest.MonkeyPatch
498498
):
499-
"""If jsonschema is not importable, a helpful ImportError must be raised."""
499+
"""If jsonschema is not importable, a helpful ImportError must be raised
500+
at factory-creation time (not at call time)."""
500501
monkeypatch.setitem(sys.modules, "jsonschema", None) # type: ignore[arg-type]
501-
schema_valid = make_schema_evaluator(_SIMPLE_SCHEMA)
502502
with pytest.raises(ImportError, match="jsonschema"):
503-
schema_valid(json.dumps({"name": "Frank", "age": 1}), {})
503+
make_schema_evaluator(_SIMPLE_SCHEMA)
504504

505505

506506
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)