Comprehensive tool validation and fixing. Returns: Tuple of (is_valid, fixed_tool_def, error_message)
(
tool_def: dict[str, Any], provider: str = "openai"
)
| 226 | |
| 227 | @staticmethod |
| 228 | def validate_and_fix_tool( |
| 229 | tool_def: dict[str, Any], provider: str = "openai" |
| 230 | ) -> tuple[bool, dict[str, Any], str | None]: |
| 231 | """ |
| 232 | Comprehensive tool validation and fixing. |
| 233 | |
| 234 | Returns: |
| 235 | Tuple of (is_valid, fixed_tool_def, error_message) |
| 236 | """ |
| 237 | if provider != "openai": |
| 238 | # For non-OpenAI providers, assume valid |
| 239 | return True, tool_def, None |
| 240 | |
| 241 | # First, try to fix the tool |
| 242 | try: |
| 243 | fixed_tool = ToolSchemaValidator.fix_openai_compatibility(tool_def) |
| 244 | |
| 245 | # Then validate the fixed version |
| 246 | validation = ToolSchemaValidator.validate_openai_schema(fixed_tool) |
| 247 | |
| 248 | return validation.is_valid, fixed_tool, validation.error_message |
| 249 | |
| 250 | except Exception as e: |
| 251 | return False, tool_def, f"Error during fix/validation: {str(e)}" |