microsoft/graphrag · error · ValueError
MetricsConfig.writer needs to be set to create a…
Error message
MetricsConfig.writer needs to be set to create a MetricsWriter.
What it means
create_metrics_writer throws this ValueError when MetricsConfig.writer is unset (None or empty), because there is no strategy to dispatch on. It is the guard clause at the top of the factory function, before any registry lookup happens. The writer is required because every metrics store needs a MetricsWriter to emit records.
Solutions
- Set MetricsConfig.writer to a valid MetricsWriterType value (e.g. 'log' or 'file') before creating the store
- If loading config from file, ensure the writer key is present and spelled correctly
- Set a default in your config model (writer: MetricsWriterType = MetricsWriterType.Log) so it is never empty
Example fix
# before config = MetricsConfig(store="memory") # after config = MetricsConfig(store="memory", writer=MetricsWriterType.Log)
Defensive patterns
Strategy: validation
Validate before calling
if not metrics_config.writer:
metrics_config = metrics_config.model_copy(update={"writer": "log"}) Type guard
def has_writer(cfg) -> bool:
return bool(cfg.writer) Try / catch
try:
writer = create_metrics_writer(cfg)
except ValueError as e:
if "needs to be set" in str(e):
cfg.writer = "log"
writer = create_metrics_writer(cfg)
else:
raise Prevention
- Always set writer when constructing MetricsConfig
- Give the field a default in your own config model
- Fail fast on empty required fields during config validation
When it happens
Trigger: Calling create_metrics_store (directly or via create_completion/create_embedding) with a MetricsConfig where writer was never set, e.g. MetricsConfig(store='memory') with writer omitted or explicitly None.
Common situations: New users constructing MetricsConfig partially, config deserialization dropping optional fields, or assuming a default writer exists when none is defined.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- MetricsConfig.store ' ' is not registered in the…
- MetricsConfig.writer
- MetricsConfig.processor
- RateLimitConfig.type
- RetryConfig.type ' ' is not registered in the RetryFactory…
AI-assisted analysis of microsoft/graphrag@f40e9a26ce (2026-08-27).
Data as JSON: /api/errors/398171e91e873cc6.
Report an issue: GitHub.
Appendix: source
Thrown at packages/graphrag-llm/graphrag_llm/metrics/metrics_writer_factory.py:65
def create_metrics_writer(metrics_config: "MetricsConfig") -> MetricsWriter:
"""Create a MetricsWriter instance based on the configuration.
Args
----
metrics_config: MetricsConfig
The configuration for the metrics writer.
Returns
-------
MetricsWriter:
An instance of a MetricsWriter subclass.
"""
strategy = metrics_config.writer
if not strategy:
msg = "MetricsConfig.writer needs to be set to create a MetricsWriter."
raise ValueError(msg)
init_args = metrics_config.model_dump()
if strategy not in metrics_writer_factory:
match strategy:
case MetricsWriterType.Log:
from graphrag_llm.metrics.log_metrics_writer import LogMetricsWriter
metrics_writer_factory.register(
strategy=MetricsWriterType.Log,
initializer=LogMetricsWriter,
scope="singleton",
)
case MetricsWriterType.File:
from graphrag_llm.metrics.file_metrics_writer import FileMetricsWriter
metrics_writer_factory.register(
strategy=MetricsWriterType.File,View on GitHub (pinned to f40e9a26ce)