38 lines
898 B
Python
38 lines
898 B
Python
"""
|
|
Schema Validator
|
|
|
|
Validates tool manifests and tool calls against their schemas.
|
|
"""
|
|
|
|
from pydantic import ValidationError
|
|
from tools.schemas.manifest import ToolManifest
|
|
from tools.schemas.tool_call import ToolCallRequest
|
|
|
|
|
|
class ManifestValidationError(Exception):
|
|
"""Manifest validation error"""
|
|
|
|
pass
|
|
|
|
|
|
class ToolCallValidationError(Exception):
|
|
"""Tool call validation error"""
|
|
|
|
pass
|
|
|
|
|
|
def validate_manifest(data: dict) -> ToolManifest:
|
|
"""Validate manifest data against ToolManifest schema"""
|
|
try:
|
|
return ToolManifest(**data)
|
|
except ValidationError as e:
|
|
raise ManifestValidationError(str(e))
|
|
|
|
|
|
def validate_tool_call(data: dict) -> ToolCallRequest:
|
|
"""Validate tool call request against ToolCallRequest schema"""
|
|
try:
|
|
return ToolCallRequest(**data)
|
|
except ValidationError as e:
|
|
raise ToolCallValidationError(str(e))
|