{"record":{"id":"b5a579ab95f22413","repo":"crewAIInc/crewAI","slug":"metadata-list-must-have-the-same-length-as-documen","errorCode":null,"errorMessage":"Metadata list must have the same length as documents list","messagePattern":"Metadata list must have the same length as documents list","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/contextualai_rerank_tool/contextual_rerank_tool.py","lineNumber":63,"sourceCode":"            import json\n\n            import requests\n\n            base_url = \"https://api.contextual.ai/v1\"\n            headers = {\n                \"accept\": \"application/json\",\n                \"content-type\": \"application/json\",\n                \"authorization\": f\"Bearer {self.api_key}\",\n            }\n\n            payload = {\"query\": query, \"documents\": documents, \"model\": model}\n\n            if instruction:\n                payload[\"instruction\"] = instruction\n\n            if metadata:\n                if len(metadata) != len(documents):\n                    raise ValueError(\n                        \"Metadata list must have the same length as documents list\"\n                    )\n                payload[\"metadata\"] = metadata\n\n            rerank_url = f\"{base_url}/rerank\"\n            result = requests.post(\n                rerank_url, json=payload, headers=headers, timeout=30\n            )\n\n            if result.status_code != 200:\n                raise RuntimeError(\n                    f\"Reranker API returned status {result.status_code}: {result.text}\"\n                )\n\n            return json.dumps(result.json(), indent=2)\n\n        except Exception as e:\n            return f\"Failed to rerank documents: {e!s}\"","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/contextualai_rerank_tool/contextual_rerank_tool.py#L45-L81","documentation":"Error \"Metadata list must have the same length as documents list\" thrown in crewAIInc/crewAI.","triggerScenarios":"Thrown at lib/crewai-tools/src/crewai_tools/tools/contextualai_rerank_tool/contextual_rerank_tool.py:63 when the library encounters an invalid state.","commonSituations":"Occurs when the metadata list passed to the Contextual AI rerank tool has a different length than the documents list. Provide one metadata entry per document.","solutions":["Provide a metadata entry for each document, or omit metadata entirely."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}