Skip to content

feat: add export_traffic() to export observations as savings-report JSONL - #21

Merged
adaamko merged 2 commits into
KRLabsOrg:mainfrom
lesbass:fix/export-traffic
Jul 9, 2026
Merged

feat: add export_traffic() to export observations as savings-report JSONL#21
adaamko merged 2 commits into
KRLabsOrg:mainfrom
lesbass:fix/export-traffic

Conversation

@lesbass

@lesbass lesbass commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Implements RuleChef.export_traffic(path) that writes observed LLM input-output pairs in the JSONL format expected by rulechef-savings:

  • Classification: {"text": "...", "llm_label": "..."}
  • NER: {"text": "...", "llm_entities": [...]}

Changes

  • rulechef/engine.py: Added export_traffic() method that iterates over buffered LLM observations and writes them as JSONL
  • benchmarks/INSPECTING_RULES.md: Documented the observe -> export_traffic -> rulechef-savings loop
  • tests/test_reports.py: Added 4 tests covering classification format, no-task auto-detection, round-trip through the savings CLI, and human-example exclusion

Verification

315 passed, 1 skipped in 3.65s
All ruff checks passed.

Rights & sign-off (required)

  • I certify that I have the right to submit this code and that it may be
    distributed under the repository's Apache-2.0 license
    (see CONTRIBUTING).

Closes #20.

@adaamko

adaamko commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Please complete the rights checkbox

…SONL

Implements RuleChef.export_traffic(path) that writes observed LLM
input-output pairs in the JSONL format expected by rulechef-savings:
- Classification: {"text": ..., "llm_label": ...}
- NER: {"text": ..., "llm_entities": [...]}

Also documents the observe -> export_traffic -> rulechef-savings loop
in benchmarks/INSPECTING_RULES.md, and adds tests including a round-trip
through the savings CLI.

Closes KRLabsOrg#20

Signed-off-by: Stefano Maffeis <lesbass@gmail.com>
@lesbass
lesbass force-pushed the fix/export-traffic branch from 409e1c2 to d034199 Compare July 3, 2026 13:14
@lesbass

lesbass commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

PR body updated with checked rights checkbox. Commit amended with DCO sign-off (Signed-off-by). Both fixes address the action_required CI state.

…penAI client creation

The RuleChef constructor creates a real OpenAI() client when none is
provided, which fails in CI without an OPENAI_API_KEY. Using a MagicMock
avoids this, consistent with other test files (test_rule_loading.py,
test_engine_observation.py).

Also add the missing MagicMock import.
@lesbass

lesbass commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Fix pushed: added client=MagicMock() to all 4 export_traffic tests so they don't try to create a real OpenAI client in CI. All 7 tests pass locally.

Could you approve the CI workflow run when you get a chance? (Fork PR needs workflow approval.)

@adaamko

adaamko commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, and sorry for the slow turnaround on the workflow approval — the run went through and everything is green. The observe → export → savings loop was exactly the missing piece, and the roundtrip test is appreciated. Merging.

@adaamko
adaamko merged commit bfe39a2 into KRLabsOrg:main Jul 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export observed traffic as savings-report JSONL (observe -> rulechef-savings loop)

2 participants