docs: improve prompt caching notebook with clearer examples and metrics,#289
Merged
Merged
Conversation
closes #288 Enhanced the notebook to better demonstrate prompt caching benefits: - Separated non-cached baseline from first/second cached calls to show cache creation vs. hit - Added timestamp to prevent unintended cache reuse across runs - Clarified that first cached call creates cache, second call benefits from it - Added explicit cache read/write token metrics to output - Included performance comparison summary showing ~2x speedup - Updated explanations to emphasize that prompt caching requires two calls - Reformatted output display for better readability - Added visual separator for performance comparison section
Notebook ChangesThis PR modifies the following notebooks: 📓
|
PedramNavid
commented
Dec 1, 2025
PedramNavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
PR Review
Recommendation: APPROVE ✅
Summary
This PR significantly improves the prompt caching notebook by separating the demonstration into three distinct phases (non-cached baseline, cache creation, cache hit), making the caching lifecycle much clearer for readers. The addition of the TIMESTAMP variable to prevent accidental cache hits across runs is a clever technique.
Actionable Feedback (5 items)
-
misc/prompt_caching.ipynb(introduction) - Add Terminal Learning Objectives (TLOs) as bullet points following the cookbook style guide pattern -
misc/prompt_caching.ipynb(pip install cell) - Use%%captureinstead of--quietfor pip install to suppress output -
misc/prompt_caching.ipynb(after introduction) - Add a Prerequisites section listing required knowledge and tools -
misc/prompt_caching.ipynb(setup cell) - Addfrom dotenv import load_dotenvandload_dotenv()to demonstrate best practices for API key handling -
misc/prompt_caching.ipynb(end of notebook) - Add a Conclusion section that maps back to learning objectives
Detailed Review
Code Quality
- Functions have clear docstrings explaining their purpose
- Output formatting improved (shows
response.content[0].textinstead of raw TextBlock) - Defensive
getattr()pattern for optional usage fields - Variable naming is clear and consistent
- Code passes ruff formatting/linting
Security
- No security issues detected
- API key handling uses
anthropic.Anthropic()which reads from environment - No hardcoded secrets or credentials
- Uses public domain content from Project Gutenberg
Suggestions
- Add a comment explaining the TIMESTAMP purpose for readers who may not immediately understand why it's needed
- Consider adding a cost comparison alongside the time comparison to show financial benefits
- Mention cache TTL (~5 minutes) in the explanations so users understand caching behavior in production
- Example 2 could benefit from expanded introductory text explaining WHY multi-turn caching matters
Positive Notes
- Excellent pedagogical structure: The three-part breakdown (baseline → cache creation → cache hit) clearly demonstrates the caching lifecycle
- Smart TIMESTAMP technique: Prevents accidental cache hits when re-running, ensuring reproducible demonstrations
- Clear explanations: Markdown cells explain what will happen before each code block
- Performance comparison table: Provides a satisfying visual summary of benefits
- Technically correct: Token counts, cache metrics, and performance benefits all accurately demonstrated
🤖 Generated with Claude Code
zealoushacker
approved these changes
Dec 16, 2025
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.
closes #288
Type of Change
Testing
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.