Spaces:
Runtime error
Runtime error
File size: 997 Bytes
595d60e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import pydantic
from typing import List
from ..schemas.agent_spec import AgentSpec
from ..schemas.conversation import ValidationError, ValidationResult
class SchemaValidator:
def validate(self, spec_dict: dict) -> ValidationResult:
errors = []
try:
AgentSpec.model_validate(spec_dict)
except pydantic.ValidationError as e:
for err in e.errors():
loc_path = ".".join(str(loc) for loc in err.get("loc", []))
errors.append(ValidationError(
code="SCHEMA_VALIDATION_FAILED",
message=f"{loc_path}: {err.get('msg')}" if loc_path else err.get('msg'),
path=loc_path or None
))
except Exception as e:
errors.append(ValidationError(
code="SCHEMA_VALIDATION_FAILED",
message=str(e),
path=None
))
return ValidationResult(valid=len(errors) == 0, errors=errors)
|