crewAIInc/crewAI · error · ValueError

Metadata list must have the same length as documents list

Error message

Metadata list must have the same length as documents list

What it means

Error "Metadata list must have the same length as documents list" thrown in crewAIInc/crewAI.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/contextualai_rerank_tool/contextual_rerank_tool.py:63

            import json

            import requests

            base_url = "https://api.contextual.ai/v1"
            headers = {
                "accept": "application/json",
                "content-type": "application/json",
                "authorization": f"Bearer {self.api_key}",
            }

            payload = {"query": query, "documents": documents, "model": model}

            if instruction:
                payload["instruction"] = instruction

            if metadata:
                if len(metadata) != len(documents):
                    raise ValueError(
                        "Metadata list must have the same length as documents list"
                    )
                payload["metadata"] = metadata

            rerank_url = f"{base_url}/rerank"
            result = requests.post(
                rerank_url, json=payload, headers=headers, timeout=30
            )

            if result.status_code != 200:
                raise RuntimeError(
                    f"Reranker API returned status {result.status_code}: {result.text}"
                )

            return json.dumps(result.json(), indent=2)

        except Exception as e:
            return f"Failed to rerank documents: {e!s}"

View on GitHub (pinned to 754d7323be)

Solutions

  1. Provide a metadata entry for each document, or omit metadata entirely.

When it happens

Trigger: Thrown at lib/crewai-tools/src/crewai_tools/tools/contextualai_rerank_tool/contextual_rerank_tool.py:63 when the library encounters an invalid state.

Common situations: 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.


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/b5a579ab95f22413. Report an issue: GitHub.