Fable 5 classifier and billing cookbook#695
Merged
Briiick merged 2 commits intoJun 9, 2026
Merged
Conversation
maheshmurag
approved these changes
Jun 9, 2026
Notebook ChangesThis PR modifies the following notebooks: 📓
|
There was a problem hiding this comment.
PR Review
Recommendation: COMMENT (PR already merged — observations for follow-up)
Summary
Adds a new cookbook (fable_5_fallback_billing/guide.ipynb) documenting how to detect Claude Fable 5 safety classifier blocks and fall back to Opus 4.8 via either server-side fallback, the SDK middleware, or manual client-side handling — including the new cache-read billing treatment and credit-token flow.
Actionable Feedback (5 items)
-
guide.ipynb(in cell withfrom anthropic import Anthropic, BetaFallbackState, ...) — section 5 reassigns the module-levelclientto one wrapped with the middleware. Anything later in the notebook (or a re-run from the top) silently picks up that middleware-bound client. Consider naming thismiddleware_clientto keep section 5 self-contained. -
guide.ipynb(in cell withredeem_credit_after_block) —extra_body=extra or NonepassesNonewhenextrais{}, which means nofallback_credit_tokenis sent on a refusal with no cached prefix. Worth a one-line comment clarifying that the no-credit path is intentional (Opus is just called normally), since the function name suggests redemption always happens. -
guide.ipynb(in cell withif not os.environ.get(\"ANTHROPIC_API_KEY\"):) — when the key is missing the cell only prints a warning; the subsequentclient.beta.messages.createcells will then raise. Eitherraisehere or wrap downstream calls in a guard so the failure mode is obvious to readers. -
registry.yaml:600-603—SafeguardsandBillingare new categories not present elsewhere in the registry (existing entries useResponses,Agent Patterns,Tools, etc.). If these are intentional new top-level buckets, that's fine; if not, consolidating under existing categories would keep the taxonomy tight. - General — all cells were committed with
outputs: []. CLAUDE.md says "Keep outputs in notebooks (intentional for demonstration)." Since the example prompts (\"Hello, world\") won't actually trigger a classifier block, consider either (a) adding a contrived prompt that does trigger one and capturing the real refusal payload, or (b) noting explicitly in the markdown that the JSON shapes are illustrative.
Detailed Review
Code Quality
- The helper functions (
fallback_hops,served_by_fallback,chat_turn,stream_turn,redeem_credit_after_block) are small, focused, and well-documented. The defensivegetattr/model_dumphandling infallback_hopsandserved_by_fallbackis appropriate given the SDK may return either Pydantic models or plain dicts. served_by_fallbackkeying offusage.iterations[*].type == \"fallback_message\"is a clean, single source of truth and the markdown correctly calls this out as the reliable check (vs. parsing in-stream events).- Model IDs
claude-fable-5andclaude-opus-4-8are forward-looking. CLAUDE.md says "use current Claude models," but a launch cookbook intentionally pre-stages the new IDs — flagging only so the team knows this notebook will need a model-check exemption or update once the IDs are GA. - Style: double quotes, 100-char-ish lines, conventional Python — matches project conventions in CLAUDE.md.
Security
- No secrets or credentials in the diff.
ANTHROPIC_API_KEYis loaded viadotenv.load_dotenv()as required by CLAUDE.md. - No injection or unsafe patterns; all calls are through the typed SDK.
Suggestions
- The streaming example (
stream_turn) silently discards the iterator —for event in streamis implied via context manager but onlyget_final_message()is called. Showing afor event in stream:body that handlestextdeltas would make the streaming section more illustrative. - The markdown in section 4 references
fallback_has_prefill_claimbut no code cell demonstrates the prefill flow. A short code snippet showing how to construct the Opus 4.8 follow-up with the partial-output prefill would close the loop. BetaRefusalFallbackMiddlewareexample never demonstratesBetaFallbackStateactually pinning a follow-up turn — it's instantiated andwith state:is used but no second turn is sent. A two-turn example would prove the sticky behavior described in the prose.
Positive Notes
- Excellent prose: the distinction between classifier blocks and model refusals, the
usage.iterationsguidance, and the anti-patterns section in §6 are the kind of subtle, easy-to-miss API behaviors that justify a cookbook existing at all. - Section 6 (anti-patterns) is the strongest part — calling out per-request fallback config, subagent behavior, the resubmit-loop pitfall, and analytics built off the wrong
modelfield will save real integration time. authors.yamlcorrectly updated with the newmikaelagraceentry; registry entry is well-formed and the cross-links inside the notebook use anchor IDs consistently.- Beta header constants (
SERVER_SIDE_FALLBACK_BETA,FALLBACK_CREDIT_BETA) are extracted to module-level constants instead of inlined — good for readability and future updates.
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.
Pull Request
Description
Type of Change
Cookbook Checklist (if applicable)
registry.yaml(run/add-registry <notebook-path>or add manually)Testing
Additional Context
Note: Pull requests that do not follow these guidelines or lack sufficient detail may be closed. This helps us maintain high-quality, useful cookbooks for the community. If you're unsure about any requirements, please open an issue to discuss before submitting a PR.