xai-org/x-algorithm · error · ValueError

sink policy {resolved}: unknown keys {sorted(unknown)}

Error message

sink policy {resolved}: unknown keys {sorted(unknown)}

What it means

_load_policy parses the optional YAML sink-policy file into the SinkPolicy dataclass. Any top-level key that is not a SinkPolicy field (minus 'source') or the free-form 'notes' key makes it raise, so typo'd or forward-incompatible policy options fail loudly instead of being silently ignored.

Source

Thrown at bdsm/runtime/score_results_sink_focal.py:290

        or os.environ.get("BDSM_SINK_POLICY", "")
        or os.path.join(os.path.dirname(os.path.abspath(__file__)), "sink_policy.yaml")
    )
    if not os.path.exists(resolved):
        log.info(f"sink policy: baked-in defaults (no policy file at {resolved})")
        return DEFAULT_POLICY
    try:
        import yaml
    except ImportError:
        log.warning(
            f"sink policy: pyyaml unavailable, IGNORING {resolved}; using baked-in defaults"
        )
        return DEFAULT_POLICY
    with open(resolved) as f:
        raw = yaml.safe_load(f) or {}
    known = {f_.name for f_ in dataclasses.fields(SinkPolicy)} - {"source"}
    unknown = set(raw) - known - {"notes"}
    if unknown:
        raise ValueError(f"sink policy {resolved}: unknown keys {sorted(unknown)}")
    kw = {}
    for k, v in raw.items():
        if k == "notes":
            continue
        if k in _POLICY_2TUPLE_TABLES:
            kw[k] = {h: (float(t[0]), float(t[1])) for h, t in v.items()}
        elif k == "official_client_app_ids":
            kw[k] = frozenset(int(x) for x in v)
        elif k == "spam_bounce_action_key":
            kw[k] = {str(h): str(a) for h, a in v.items()}
        elif k == "min_actions_for_enforcement":
            kw[k] = int(v)
        elif k in ("cusp_delta", "reply_spam_hard_suspend_tau"):
            kw[k] = float(v)
        else:
            kw[k] = str(v)
    pol = SinkPolicy(source=resolved, **kw)
    log.info(f"sink policy: LOADED {resolved} (version={pol.version})")

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Diff the YAML keys against dataclasses.fields(SinkPolicy) (the error lists the offenders)
  2. Fix typos or remove the unknown keys from the policy file
  3. If the key is from a newer sink version, upgrade the sink or drop the key until you upgrade
  4. Rely on test_shipped_policy_matches_baked_in_defaults-style checks to keep policy files valid

Example fix

# before (policy.yaml)
unknown_key: 1
challenge_fraction: 0.05
# after
challenge_fraction: 0.05
Defensive patterns

Strategy: validation

Validate before calling

import dataclasses, yaml
known = {f.name for f in dataclasses.fields(SinkPolicy)} - {'source'} | {'notes'}
raw = yaml.safe_load(open(path)) or {}
assert set(raw) <= known, f"bad keys: {set(raw) - known}"

Type guard

def policy_keys_valid(path: str) -> bool:
    raw = yaml.safe_load(open(path)) or {}
    known = {f.name for f in dataclasses.fields(SinkPolicy)} - {'source'} | {'notes'}
    return set(raw) <= known

Try / catch

try:
    policy = _load_policy(path)
except ValueError as e:
    if 'unknown keys' in str(e):
        policy = DEFAULT_POLICY  # or fix the file and reload
    else:
        raise

Prevention

When it happens

Trigger: Pointing the policy-file setting at a YAML containing a key like 'sampling_ratio' when SinkPolicy has no such field; misspelling a field ('throttle_ms' vs 'throttling_ms'); using a policy file written for a newer version of the sink.

Common situations: Hand-edited policy YAML with typos; version skew between policy file format and deployed sink; copy-pasted keys from a different config schema.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/c78c3e0463c62b75. Report an issue: GitHub.