{"record":{"id":"1408d8fa0097ead5","repo":"deepset-ai/haystack","slug":"the-provided-parameters-do-not-define-a-valid-json","errorCode":null,"errorMessage":"The provided parameters do not define a valid JSON schema","messagePattern":"The provided parameters do not define a valid JSON schema","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/tools/tool.py","lineNumber":135,"sourceCode":"        if self.function is not None and inspect.iscoroutinefunction(self.function):\n            raise ValueError(\n                f\"`function` must be a synchronous function. \"\n                f\"The function '{self.function.__name__}' is a coroutine function. \"\n                f\"Pass it as `async_function` instead.\"\n            )\n\n        # `async_function` must be a coroutine function defined with `async def`.\n        if self.async_function is not None and not inspect.iscoroutinefunction(self.async_function):\n            raise ValueError(\n                f\"`async_function` must be a coroutine function defined with `async def`. \"\n                f\"Got '{getattr(self.async_function, '__name__', repr(self.async_function))}'.\"\n            )\n\n        # Check that the parameters define a valid JSON schema\n        try:\n            Draft202012Validator.check_schema(self.parameters)\n        except SchemaError as e:\n            raise ValueError(\"The provided parameters do not define a valid JSON schema\") from e\n\n        # Validate outputs structure if provided\n        if self.outputs_to_state is not None:\n            for key, config in self.outputs_to_state.items():\n                if not isinstance(config, dict):\n                    raise TypeError(f\"outputs_to_state configuration for key '{key}' must be a dictionary\")\n                if \"source\" in config and not isinstance(config[\"source\"], str):\n                    raise ValueError(f\"outputs_to_state source for key '{key}' must be a string.\")\n                if \"handler\" in config and not callable(config[\"handler\"]):\n                    raise ValueError(f\"outputs_to_state handler for key '{key}' must be callable\")\n\n            # Validate that outputs_to_state source keys exist as valid tool outputs\n            valid_outputs: set[str] | None = self._get_valid_outputs()\n            if valid_outputs is not None:\n                for state_key, config in self.outputs_to_state.items():\n                    source = config.get(\"source\")\n                    if source is not None and source not in valid_outputs:\n                        raise ValueError(","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/tools/tool.py#L117-L153","documentation":"The Tool's `parameters` must be a valid JSON Schema draft 2020-12. __post_init__ runs jsonschema's Draft202012Validator.check_schema and raises ValueError (chaining the SchemaError) if the schema itself is malformed, so that invalid tool signatures fail fast at construction time.","triggerScenarios":"Tool(name=..., function=..., parameters=<dict that violates meta-schema>) e.g. parameters={\"type\": \"objct\"}, missing \"type\"/\"properties\" structure, wrong types like \"properties\": [\"a\"], or not a dict at all (parameters=None or a JSON string).","commonSituations":"Hand-writing JSON schemas with typos; copying schemas from OpenAI/Anthropic docs using unsupported or older keywords; LLM-generated schema snippets pasted in; passing a JSON string instead of a parsed dict.","solutions":["Fix the schema so it passes Draft202012Validator.check_schema (run this check standalone to see the chained SchemaError details).","Correct common typos: \"type\": \"object\", \"properties\": {<name>: {...}}, \"required\": [list of strings].","If a schema string is available, json.loads it into a dict before constructing the Tool.","Simplify to a minimal valid schema: {\"type\": \"object\", \"properties\": {...}} and build up incrementally, validating each step."],"exampleFix":"// before\nTool(name=\"search\", function=search, parameters={\"type\": \"objct\", \"properties\": {\"q\": {\"type\": \"string\"}}})\n\n// after\nTool(name=\"search\", function=search, parameters={\"type\": \"object\", \"properties\": {\"q\": {\"type\": \"string\"}}, \"required\": [\"q\"]})","handlingStrategy":"validation","validationCode":"from jsonschema import Draft202012Validator\nDraft202012Validator.check_schema(params)  # raises SchemaError before Tool construction","typeGuard":"import json\nfrom typing import Any\n\ndef is_valid_schema(params: Any) -> bool:\n    if not isinstance(params, dict):\n        return False\n    try:\n        Draft202012Validator.check_schema(params)\n        return True\n    except Exception:\n        return False","tryCatchPattern":"try:\n    tool = Tool(name=\"t\", function=f, parameters=params)\nexcept ValueError as e:\n    logger.error(f\"Invalid JSON schema for tool parameters: {e.__cause__}\")\n    raise","preventionTips":["Run Draft202012Validator.check_schema on schemas in CI/tests before shipping","Use schema-building helpers or typed-dataclass-to-schema generators instead of hand-written dicts","Ensure parameters is a parsed dict, never a JSON string"],"tags":["python","json-schema","tool","validation"],"backgroundTag":"invalid-json-schema","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}