Skip to content

Commit 2092f1c

Browse files
committed
Fix KeyError in 05_crafting_data_for_llms
Use .get() with default value to handle missing profile_text key.
1 parent a92fe1e commit 2092f1c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

python-recipes/context-engineering/notebooks/section-4-optimizations/05_crafting_data_for_llms.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@
594594
"\n",
595595
"profile_data = redis_client.get(f\"user_profile:{user_data['student_id']}\")\n",
596596
"profile_json = json.loads(profile_data) if profile_data else {}\n",
597-
"profile_text = profile_json['profile_text']\n",
597+
"profile_text = profile_json.get('profile_text', 'No profile available')\n",
598598
"\n",
599599
"system_prompt = f\"\"\"You are a class scheduling agent for Redis University.\n",
600600
"\n",

0 commit comments

Comments
 (0)