microsoft/graphrag · error · ValueError

MetricsConfig.writer '{strategy}' is not registered in the M

Error message

MetricsConfig.writer '{strategy}' is not registered in the MetricsWriterFactory. Registered strategies: {', '.join(metrics_writer_factory.keys())}

What it means

This ValueError is raised by create_metrics_writer when MetricsConfig.writer holds a value that is not in the metrics_writer_factory registry. It is the catch-all branch of the match statement that lazily registers built-in writers (Log, File). Any other value falls through and the message enumerates registered strategies for easy correction.

Source

Thrown at packages/graphrag-llm/graphrag_llm/metrics/metrics_writer_factory.py:89

            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,
                    initializer=FileMetricsWriter,
                    scope="singleton",
                )
            case _:
                msg = f"MetricsConfig.writer '{strategy}' is not registered in the MetricsWriterFactory. Registered strategies: {', '.join(metrics_writer_factory.keys())}"
                raise ValueError(msg)

    return metrics_writer_factory.create(strategy=strategy, init_args=init_args)

View on GitHub (pinned to f40e9a26ce)

Solutions

  1. Set MetricsConfig.writer to one of the strategies listed in the error message
  2. Fix typos/outdated values in YAML/JSON config
  3. Register your custom writer with metrics_writer_factory.register(strategy=..., initializer=YourWriter, scope=...) before creation
  4. Constrain the field to a Literal/enum in your own config layer to catch invalid values early

Example fix

# before
config = MetricsConfig(store="memory", writer="stdoutt")

# after
config = MetricsConfig(store="memory", writer="log")
Defensive patterns

Strategy: validation

Validate before calling

from graphrag_llm.metrics import metrics_writer_factory

if metrics_config.writer not in metrics_writer_factory:
    raise ValueError(f"Invalid writer {metrics_config.writer!r}; valid: {list(metrics_writer_factory.keys())}")

Type guard

from graphrag_llm.metrics import metrics_writer_factory

def is_valid_writer(name: str) -> bool:
    return name in metrics_writer_factory

Try / catch

try:
    writer = create_metrics_writer(cfg)
except ValueError as e:
    if "not registered in the MetricsWriterFactory" in str(e):
        raise  # config bug: fix writer value
    raise

Prevention

When it happens

Trigger: Calling create_metrics_store with a writer value that is misspelled, an unknown string, or a custom writer class name that was not registered via metrics_writer_factory.register(...).

Common situations: Typos in config files, enum renames between versions, or third-party writer integrations that forgot to call register.

Related errors


AI-assisted analysis of microsoft/graphrag@f40e9a26ce (2026-08-27). Data as JSON: /api/errors/fcebbf6e8d923d97. Report an issue: GitHub.