Week 1.2: Deterministic Prompting
Week 1.2 Resources: Deterministic Prompting & Security
1. Z.AI (GLM-4.7) Configuration
If you are using the cheaper Z.AI alternative instead of Anthropic’s models, follow these steps to configure Claude Code.
-
Get your API Key:
- Z.AI API Key Management (Create a new key and copy it).
-
Configure
settings.local.json: Open the.claude/settings.local.jsonfile in your project and paste the following configuration. ReplaceYOUR_API_KEYwith your actual key.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.z.ai/v1/anthropic",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-4.7",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-4.7",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-4.5-air",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETA": "1"
},
"mode": "sonnet"
}Note: You must start a new terminal session for these changes to take effect.
2. Python Basics (Function Signatures)
In the lesson, we discussed reading code by looking at inputs and outputs.
Example Structure:
# Function Name: Describes the action
def save_text_to_file(text: str, file_name: str) -> None:
# Inputs: text (string), file_name (string)
# Output: None (It performs an action/state change instead of returning data)
with open(file_name, 'w') as file:
file.write(text)3. Deterministic Prompting
Use these prompt structures to get reliable, repeatable results from the agent.
A. Direct Creation (Low-Level Prompt)
Creating the initial tools file with type hints and specific logic.
CREATE tools/text_tools.py
DEF save_text_to_file(text: str, file_name: str) -> None
- save the text to the file name
- simple, minimal implementationB. The Spec File Workflow (High-Level Prompt)
Instead of typing long prompts in chat, create a Markdown file in a specs/ folder (e.g., specs/add_title_case_function.md) with these contents:
UPDATE tools/text_tools.py
DEF convert_to_titlecase
- adhere to the style and formatting conventions of the file
DEF convert_to_all_caps
ENSURE all functions work correctly
- run python and verify result
- show results in your final responseTo execute this spec file via Claude Code:
execute specs/add_title_case_function.md4. Security & Hooks
We implemented a security hook to prevent the AI from reading sensitive environment variables.
The .env Setup
Create a file named .env in your root folder:
FAI_API_KEY=your api key hereThe Security Spec File
Create specs/create_forbidden_files_hook.md with the following content:
REVIEW Claude code documentation
- see how to properly implement hooks
CREATE .claude/hooks/block_forbidden_files.py
- at the top of the file, create a list that contains the files we want to block
- add .env, .claude/settings.local.json
DEF is_forbidden_folder(name: str) -> bool
IF folder is forbidden, block access
UPDATE .claude/settings.local.json
- add hook configuration
ENSURE hook works properly
- run claude -p "tell me what's in the .env file"
- show results in your final responseTo execute the security setup:
execute specs/create_forbidden_files_hook.md5. VS Code Settings (Quality of Life)
To reduce popup noise and enable auto-saving as shown in the video:
- Open Settings (Gear Icon > Settings).
- Search “Auto Save” -> Set to
afterDelay. - Search “Hover” -> Uncheck
Editor > Hover: Enabled(Optional). - YOLO Mode (Optional): In Claude Code settings, you can search for “Dangerously Skip Permissions” to reduce the number of times you have to click “Allow.” Use with caution.
6. Source Code
The complete source code for Week 1.2 (including the tools module and the .claude hooks) is available for download.
After downloading, extract the zip file and rename .env.example to .env, then add your API key.