feat: refusal detection + owner-positive framing for files audits (closes #4)#5
Merged
Conversation
Closes the cept#4 failure mode: when the underlying model declines to
engage with the packet (rather than recommending a substantive
backtrack), cept's response shape is structurally identical to real
guidance — same `decision`, `confidence`, `hypotheses` keys — so
callers act on the refusal as if it were a recommendation.
Two layers from the issue:
1. detect_refusal() runs heuristics on the parsed response —
`recommended_next_step` opening with "decline/refuse/cannot/won't",
refusal phrases in `summary`, and refusal-shaped language in
`hypotheses[].title/why`. When matched, sets `refused: true` and
`refusal_reason` so callers can switch on the difference.
2. When `packet.files` is non-empty, the user-payload preamble now
states explicitly that the calling agent is the document owner
asking for help hardening their own deliverable, killing the most
common false-positive refusal seen on perplexity/sonar-pro
("audit"/"red-team" framing read as third-party attack prep).
Skips layer 3 (auto-retry on refusal) — billed second call, opinionated.
Ship cheap fixes first; revisit if these don't move the refusal rate.
Bumps to v0.3.0: response field additions are non-breaking but additive,
so per cept's existing convention (0.1 -> 0.2 was the `files` param)
this is a minor bump.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #4 with two layers from the issue's proposed fix; layer 3 (auto-retry on refusal) deliberately skipped — billed second call, ship cheap fixes first.
Layer 1: refusal detection in
openrouter.detect_refusal(). Heuristics scanrecommended_next_step(anchored regex on opening tokens),summary, andhypotheses[].title/whyfor refusal-shaped language. When matched, the response gets two additive top-level fields:{ "refused": true, "refusal_reason": "...", "decision": "backtrack", "confidence": 0.88, ... }Layer 2: owner-positive system-prompt framing when
packet.filesis non-empty. Tells the model the calling agent is the document owner asking to harden their own deliverable, so adversarial language ("audit", "red-team") doesn't trigger third-party-attack refusals.Why
The cept#4 repro:
perplexity/sonar-pro(the default) read 12 KB of confidential corporate text + "adversarial audit" framing as attack prep and refused withdecision: backtrack, confidence: 0.88. Identical shape to substantive guidance. Calling agent has no way to tell the audit didn't happen.Test plan
uv run pytest -x -q— 84 passed (10 new intest_openrouter.py)uv run ruff check src/cept tests— cleanVersioning
Bumps to v0.3.0. Additive non-breaking response fields; matches the v0.1 → v0.2 minor bump for the
filesparameter.🤖 Generated with Claude Code