mirror of
https://github.com/p-e-w/heretic.git
synced 2026-10-02 08:51:27 -07:00
fix: validate scorer instance names in config (#407)
* fix: validate scorer instance names in config * fix: run scorer config tests in CI * fix: drop redundant UV_PYTHON env and quote unittest pattern * fix: report precise scorer name validation errors
This commit is contained in:
@@ -9,6 +9,7 @@ from pydantic import (
|
||||
Field,
|
||||
NonNegativeInt,
|
||||
PositiveInt,
|
||||
field_validator,
|
||||
)
|
||||
from pydantic_settings import (
|
||||
BaseSettings,
|
||||
@@ -123,6 +124,23 @@ class ScorerConfig(BaseModel):
|
||||
),
|
||||
)
|
||||
|
||||
@field_validator("instance_name")
|
||||
@classmethod
|
||||
def validate_instance_name(cls, value: str | None) -> str | None:
|
||||
if value is None:
|
||||
return value
|
||||
|
||||
if not value.strip():
|
||||
raise ValueError("cannot be empty or whitespace")
|
||||
|
||||
if "." in value:
|
||||
raise ValueError("'.' is not allowed")
|
||||
|
||||
if any(char.isspace() for char in value):
|
||||
raise ValueError("whitespace is not allowed")
|
||||
|
||||
return value
|
||||
|
||||
|
||||
class BenchmarkSpecification(BaseModel):
|
||||
task: str = Field(
|
||||
|
||||
@@ -67,18 +67,6 @@ class Evaluator:
|
||||
# Instantiate scorers.
|
||||
instance_name = config.instance_name or None
|
||||
|
||||
if instance_name is not None:
|
||||
if not instance_name.strip():
|
||||
raise ValueError(
|
||||
f"Invalid instance_name {instance_name} for scorer {scorer_cls.__name__}: "
|
||||
"cannot be empty or whitespace"
|
||||
)
|
||||
if "." in instance_name or " " in instance_name:
|
||||
raise ValueError(
|
||||
f"Invalid instance_name {instance_name} for scorer {scorer_cls.__name__}: "
|
||||
"'.' and whitespace are not allowed"
|
||||
)
|
||||
|
||||
raw_settings = self._get_scorer_settings_raw(
|
||||
scorer_cls=scorer_cls, instance_name=instance_name
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user