in gemini/prompts/prompt_optimizer/vapo_lib.py [0:0]
def validate_tools(spec: str) -> None:
"""Validates the tools specification."""
# Define the JSON schema for validation
schema = {
"type": "object",
"properties": {
"tools": {
"type": "array",
"minItems": 1, # Ensures that 'tools' is not an empty array
"items": {
"type": "object",
"properties": {
"function_declarations": {
"type": "array",
# Ensures this is not an empty array
"minItems": 1,
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"description": {"type": "string"},
"parameters": {
"type": "object",
"properties": {
"type": {"type": "string"},
"properties": {"type": "object"},
"required": {
"type": "array",
"items": {"type": "string"},
},
},
"required": ["type", "properties"],
},
},
"required": ["name", "description", "parameters"],
},
}
},
"required": ["function_declarations"],
},
}
},
"required": ["tools"],
}
json_spec = json.loads(spec)
try:
# Validate the JSON specification against the schema
validate(instance=json_spec, schema=schema)
except ValidationError as e:
raise ValueError(f"Invalid Tools specification: {e}") from e