Skip to content

rulechef-savings: support NER/extraction traffic, not just classification #19

Description

@adaamko

Problem

rulechef-savings only understands classification traffic: it compares the rule's label string to the observed llm_label (rulechef/savings.py, the chef.extract(...)["label"] comparison). NER/extraction traffic — where the LLM returns entity lists — can't be analyzed, even though that's exactly the TAB-style use case.

Current behavior

label = (out or {}).get("label") or ""
ok = str(label).strip().lower() == str(r.get("llm_label", "")).strip().lower()

A traffic row with {"text": ..., "llm_entities": [...]} is silently treated as unanswered.

What to do

  1. Accept NER traffic rows: {"text": ..., "llm_entities": [{"text","start","end","type"}, ...]}.
  2. Define "answered": rules produced a non-empty entity list. Define "agreement": span-set comparison against llm_entities — reuse _match_entities from rulechef/evaluation.py (mode "text" or "partial") and report micro-F1 vs the LLM instead of exact string match.
  3. Keep the report layout; the per-rule table's "agreement" column becomes F1-vs-LLM for NER traffic.
  4. Auto-detect the traffic type from the first row (llm_label vs llm_entities).

Acceptance

rulechef-savings --rules <TAB rules> --traffic <ner_traffic.jsonl> produces a report with sensible coverage/agreement; add a test next to tests/test_reports.py::test_savings_cli with a 2-row NER traffic file.

Start here

git clone https://github.com/KRLabsOrg/rulechef.git && cd rulechef
pip install -e ".[dev,grex]" && pytest tests/test_reports.py -q
rulechef-savings --rules benchmarks/results/results_banking77_new.json \
  --traffic benchmarks/results/sample_traffic_banking77.jsonl --out s.html  # the classification path that works today

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions