microsoft/graphrag · error · ValueError
ModelConfig.mock_responses must be a non-empty list of embed
Error message
ModelConfig.mock_responses must be a non-empty list of embedding responses.
What it means
MockLLMEmbedding requires ModelConfig.mock_responses to be a non-empty list; it builds fake embedding vectors from it for testing. None, a non-list, or an empty list is rejected in __init__.
Source
Thrown at packages/graphrag-llm/graphrag_llm/embedding/mock_llm_embedding.py:48
_mock_responses: list[float]
_mock_index: int = 0
def __init__(
self,
*,
model_config: "ModelConfig",
tokenizer: "Tokenizer",
metrics_store: "MetricsStore",
**kwargs: Any,
):
"""Initialize MockLLMEmbedding."""
self._tokenizer = tokenizer
self._metrics_store = metrics_store
mock_responses = model_config.mock_responses
if not isinstance(mock_responses, list) or len(mock_responses) == 0:
msg = "ModelConfig.mock_responses must be a non-empty list of embedding responses."
raise ValueError(msg)
if not all(isinstance(resp, float) for resp in mock_responses):
msg = "Each item in ModelConfig.mock_responses must be a float."
raise ValueError(msg)
self._mock_responses = mock_responses # type: ignore
def embedding(
self, /, **kwargs: Unpack["LLMEmbeddingArgs"]
) -> "LLMEmbeddingResponse":
"""Sync embedding method."""
input = kwargs.get("input")
response = create_embedding_response(
self._mock_responses, batch_size=len(input)
)
self._mock_index += 1
return response
View on GitHub (pinned to f40e9a26ce)
Solutions
- Set mock_responses to a non-empty list of floats, e.g. mock_responses: [0.1, 0.2, 0.3]
- In tests, build the ModelConfig with explicit mock_responses rather than reusing a production config
Example fix
# before ModelConfig(type=LLMProviderType.MockLLM, model="mock") # after ModelConfig(type=LLMProviderType.MockLLM, model="mock", mock_responses=[0.1, 0.2, 0.3])
Defensive patterns
Strategy: validation
Validate before calling
mr = getattr(model_config, "mock_responses", None)
if isinstance(mr, list) and len(mr) > 0 and all(isinstance(x, float) for x in mr):
mock = MockLLMEmbedding(model_config, tokenizer, metrics_store)
else:
raise ValueError("mock_responses must be a non-empty list of floats") Type guard
def has_valid_mock_responses(cfg: ModelConfig) -> bool:
mr = cfg.mock_responses
return isinstance(mr, list) and len(mr) > 0 and all(isinstance(x, float) for x in mr) Prevention
- Centralize mock ModelConfig construction in a test fixture that always sets mock_responses=[0.1, 0.2, 0.3]
- Never reuse production configs for mock-backed tests
When it happens
Trigger: Creating MockLLMEmbedding (or create_embedding with the mock type) where model_config.mock_responses is None, a scalar, or [].
Common situations: Writing unit tests with a mock model config but forgetting mock_responses; settings.yaml for tests omitting mock_responses; passing a string instead of a list.
Related errors
- Each item in ModelConfig.mock_responses must be a float.
- ModelConfig.type '{strategy}' is not registered in the Compl
- api_base must be specified with the 'azure' model provider.
- azure_deployment_name should not be specified for non-Azure
- api_key should not be set when using Azure Managed Identity.
AI-assisted analysis of microsoft/graphrag@f40e9a26ce (2026-08-27).
Data as JSON: /api/errors/e986c5a26af42da7.
Report an issue: GitHub.