headroomlabs-ai/headroom · error · ValueError
unknown importance context: {context}
Error message
unknown importance context: {context} What it means
Raised by the Python shim around the Rust _rust_score_line in error_detection.py: the Rust binding returns None for unknown context names (to dodge a pyo3/clippy issue), and this shim converts that None into the explicit ValueError callers expect. Context names are the scoring contexts like error/warning/importance/security/markdown; anything else is rejected.
Source
Thrown at headroom/transforms/error_detection.py:67
)
def score_line(line: str, context: str = "text") -> tuple[str | None, float, float]:
"""Score `line` against the default Rust keyword detector.
Returns ``(category | None, priority, confidence)``. ``category`` is
one of ``error|warning|importance|security|markdown`` or ``None`` if
nothing matched.
Raises :class:`ValueError` for unknown context names. The Rust
binding returns ``None`` for unknown contexts to dodge a
pyo3-0.22 + clippy false positive on ``PyResult``-returning
``#[pyfunction]``s; this shim translates that into the explicit
Python error every caller would expect.
"""
result = _rust_score_line(line, context)
if result is None:
raise ValueError(f"unknown importance context: {context}")
return cast("tuple[str | None, float, float]", result)
_REGISTRY: dict[str, list[str]] = _rust_keyword_registry_snapshot()
def _alternation(words: list[str]) -> str:
"""Compile a `\b(w1|w2|…)\b` regex source from the Rust-supplied list.
The keywords are static (compiled once on import) so we don't need
`re.escape` for the current set, but using it keeps the shim
correct if a future Rust update adds a regex meta-character.
"""
escaped = [re.escape(w) for w in words]
return r"\b(" + "|".join(escaped) + r")\b"
# ─── Canonical keyword sets (pulled from Rust at import time) ───────────────View on GitHub (pinned to 322425c43b)
Solutions
- Use an exact, known context name (check the Rust keyword registry snapshot via the module's exposed registry).
- Whitelist contexts at the call site before invoking score_line.
- After upgrading the native extension, re-check the supported context list if you use non-core contexts.
Example fix
# before
score_line(line, context="errors") # ValueError: unknown importance context
# after
_VALID_CONTEXTS = {"error", "warning", "importance", "security", "markdown"}
score_line(line, context=context if context in _VALID_CONTEXTS else "importance") Defensive patterns
Strategy: validation
Validate before calling
_VALID = {"error", "warning", "importance", "security", "markdown"}
if context not in _VALID:
raise ValueError(f"bad context {context!r}; expected one of {sorted(_VALID)}")
score_line(line, context) Type guard
def is_valid_importance_context(ctx: str) -> bool:
return ctx in {"error", "warning", "importance", "security", "markdown"} Try / catch
try:
cat, prio, conf = score_line(line, context)
except ValueError as e:
if "unknown importance context" in str(e):
cat, prio, conf = score_line(line, "importance") # safe default
else:
raise Prevention
- Whitelist contexts before calling score_line.
- Don't pass free-form/LLM-generated strings as context.
- After upgrading the native extension, re-check the supported context set.
When it happens
Trigger: Calling score_line (the shim) with a context string that is not one of the recognized contexts — typo like 'err' vs 'error', or a new context added on the caller side but not in the Rust keyword registry.
Common situations: Passing a context sourced from config or an LLM prompt; version skew where the Python package and the compiled Rust extension disagree on the context set.
Related errors
- items_json must be JSON: {e}
- doc_json must be JSON: {e}
- {wheel.name} does not contain headroom/_core native extensio
- invalid pipeline config TOML: {0}
- recommendations file not found: {0}
AI-assisted analysis of headroomlabs-ai/headroom@322425c43b (2026-08-15).
Data as JSON: /api/errors/6271e59f77f9b264.
Report an issue: GitHub.