LLM Engineering Basics · Course lab · about 360 minutes · 6 tasks · marked out of 100, pass at 60
A grounded assistant with an eval gate and a cost sheet
The situation
Build the fee-desk assistant properly: scripted API calls with the system prompt as the builder's lever, a cost sheet with real prices, structured extraction that returns null instead of inventing, a red-team pass with defences, a miniature RAG over ten chunks of academy knowledge, and a 20-case eval runner that scores every change before it ships. The final paragraph reads like a client deliverable because it is one.
What you'll be able to show
- Control behaviour through the system prompt and measure what it costs
- Extract structured data with validation and honest nulls
- Attack your own assistant and defend it, reporting what still gets through
- Ground answers in retrieved context and gate changes with an eval pass rate
What you need
- An LLM provider key on a free tier, Python, a .env file
- The provider's pricing page and embedding endpoint
- Ten chunks of invented-but-realistic academy knowledge (fees, timings, policies)
Tasks
-
1The builder's leverStore the key in .env (verify .gitignore). Make three calls with a narrow system prompt and three user messages. Change only the system prompt — tone, language, refusals — and observe the change.A correct result: Six outputs showing behaviour moved by the system prompt alone.
-
2The cost sheetWith real current prices: count the system prompt's tokens (usage field or a tokenizer), an average question, a three-sentence answer. Compute cost per conversation and per month at 100/day and 2,000/day. Halve the prompt without losing correctness and recompute. Write the one-line conclusion.A correct result: A sheet with two monthly figures before and after, and the conclusion about prompt length × traffic.
-
3Extraction that admits ignoranceAdd an /extract command that asks for a JSON lead record ({name, course, city, phone}) with the schema in the prompt, try/except parsing, one retry with the error, and validation. Test with a cooperative conversation and a messy one with fields missing.A correct result: Missing fields come back as null, never invented; the retry path is exercised once.
-
4Red team, then defendAttempt a direct override, system-prompt extraction, a fake discount authorisation, and an indirect attack pasted inside an enquiry. Record what worked. Apply two defences and re-attack. Write the three-line report: what still gets through and its blast radius.A correct result: Four attacks before and after, and the honest three-line report.
-
5Miniature RAG with an evalEmbed ten knowledge chunks; similarity search in plain Python; a grounded prompt that answers only from context. Build a 10-question eval set with expected sources, log retrieved chunks per question, find one failure, diagnose retrieval vs generation from the log, fix the right layer, re-run.A correct result: An eval run before and after the fix, with the diagnosis written down.
-
6The gate and the paragraphExtend the eval to 20 cases including 3 injections (expected: refusal) and 3 out-of-knowledge questions (expected: I do not know). Write the runner that prints a pass rate. Run it before and after one deliberate prompt change. Then write the three hiring-signal sentences for your assistant: eval pass rate, cost at 500 questions/day, attack behaviour.A correct result: Two pass rates around a change, and the three-sentence paragraph.
What to hand in
The repo (no key in it), the cost sheet, the extraction test outputs, the red-team report, the eval runs before and after, and the three-sentence paragraph.
How it is marked
| Criterion | Points |
|---|---|
| System-prompt control shown and key kept out of the repo | 10 |
| Cost sheet with real prices and a conclusion | 15 |
| Extraction validates and returns honest nulls | 15 |
| Red team run, defended, honestly reported | 20 |
| RAG with an eval, one failure diagnosed and fixed at the right layer | 20 |
| 20-case gate working and the client paragraph written | 20 |
| Total · pass at 60 | 100 |
صورتحال
fee-desk assistant ٹھیک سے بنائیں: scripted API calls جہاں system prompt بنانے والے کا lever ہو، حقیقی قیمتوں والی cost sheet، structured extraction جو ایجاد کرنے کے بجائے null واپس کرے، دفاع کے ساتھ red-team pass، academy کی معلومات کے دس chunks پر چھوٹا RAG، اور 20 cases کا eval runner جو ہر تبدیلی کو بھیجنے سے پہلے score کرے۔ آخری paragraph client کی deliverable جیسا پڑھا جائے کیونکہ یہ وہی ہے۔
آپ کیا دکھا سکیں گے
- system prompt سے رویّہ قابو کرنا اور ناپنا کہ اس کی لاگت کیا ہے
- validation اور ایماندار nulls کے ساتھ structured data نکالنا
- اپنے assistant پر حملہ کرنا اور دفاع کرنا، رپورٹ کرتے ہوئے کہ اب بھی کیا نکل جاتا ہے
- retrieved context میں جوابوں کو grounded رکھنا اور eval pass rate سے تبدیلیوں پر gate لگانا
آپ کو کیا چاہیے
- free tier پر LLM provider کی key، Python، ایک .env file
- provider کا pricing page اور embedding endpoint
- academy کی فرضی مگر حقیقت پسندانہ معلومات کے دس chunks (فیسیں، اوقات، policies)
کام
-
1بنانے والے کا leverkey کو .env میں رکھیں (.gitignore verify کریں)۔ ایک محدود system prompt اور تین user messages کے ساتھ تین calls کریں۔ صرف system prompt بدلیں — لہجہ، زبان، انکار — اور تبدیلی کا مشاہدہ کریں۔درست نتیجہ: چھ outputs جو دکھائیں کہ رویّہ صرف system prompt سے بدلا۔
-
2cost sheetحقیقی موجودہ قیمتوں کے ساتھ: system prompt کے tokens گنیں (usage field یا tokenizer)، اوسط سوال، تین جملوں کا جواب۔ فی گفتگو اور فی مہینہ لاگت 100/دن اور 2,000/دن پر نکالیں۔ درستی کھوئے بغیر prompt آدھا کریں اور دوبارہ حساب لگائیں۔ ایک line کا نتیجہ لکھیں۔درست نتیجہ: پہلے اور بعد کے دو ماہانہ ہندسوں والی sheet، اور prompt کی لمبائی × traffic پر نتیجہ۔
-
3ایسی extraction جو لاعلمی تسلیم کرےایک /extract command شامل کریں جو JSON lead record ({name, course, city, phone}) مانگے، schema prompt میں، try/except parsing، error کے ساتھ ایک retry، اور validation۔ ایک تعاون کرنے والی گفتگو اور ایک بے ترتیب گفتگو سے آزمائیں جس میں fields غائب ہوں۔درست نتیجہ: غائب fields null واپس آئیں، کبھی ایجاد نہ ہوں؛ retry کا راستہ ایک بار چلے۔
-
4red team، پھر دفاعبراہِ راست override، system-prompt نکلوانا، جعلی discount کی اجازت، اور enquiry کے اندر paste کیا ہوا بالواسطہ حملہ آزمائیں۔ لکھیں کیا کامیاب ہوا۔ دو دفاع لگائیں اور دوبارہ حملہ کریں۔ تین lines کی رپورٹ لکھیں: اب بھی کیا نکلتا ہے اور اس کا نقصان کا دائرہ۔درست نتیجہ: پہلے اور بعد کے چار حملے، اور ایماندار تین lines کی رپورٹ۔
-
5eval کے ساتھ چھوٹا RAGدس knowledge chunks embed کریں؛ سادہ Python میں similarity search؛ ایک grounded prompt جو صرف context سے جواب دے۔ متوقع sources کے ساتھ 10 سوالوں کا eval set بنائیں، ہر سوال کے retrieved chunks log کریں، ایک ناکامی ڈھونڈیں، log سے retrieval بمقابلہ generation کی تشخیص کریں، صحیح layer ٹھیک کریں، دوبارہ چلائیں۔درست نتیجہ: fix سے پہلے اور بعد کا eval run، تشخیص لکھی ہوئی۔
-
6gate اور paragrapheval کو 20 cases تک بڑھائیں جن میں 3 injections (متوقع: انکار) اور 3 علم سے باہر کے سوال (متوقع: I do not know) شامل ہوں۔ runner لکھیں جو pass rate print کرے۔ ایک جان بوجھ کر کی گئی prompt تبدیلی سے پہلے اور بعد میں چلائیں۔ پھر اپنے assistant کے لیے hiring-signal کے تین جملے لکھیں: eval pass rate، 500 سوال/دن پر لاگت، حملے پر رویّہ۔درست نتیجہ: ایک تبدیلی کے ارد گرد دو pass rates، اور تین جملوں کا paragraph۔
کیا جمع کروانا ہے
repo (اس میں key نہیں)، cost sheet، extraction کے test outputs، red-team رپورٹ، پہلے اور بعد کے eval runs، اور تین جملوں کا paragraph۔
نمبر کیسے ملیں گے
| معیار | نمبر |
|---|---|
| system-prompt کا قابو دکھایا اور key repo سے باہر رکھی | 10 |
| حقیقی قیمتوں والی cost sheet اور نتیجہ | 15 |
| extraction validate کرتی ہے اور ایماندار nulls واپس کرتی ہے | 15 |
| red team چلی، دفاع ہوا، ایمانداری سے رپورٹ ہوا | 20 |
| eval والا RAG، ایک ناکامی صحیح layer پر تشخیص اور ٹھیک ہوئی | 20 |
| 20 cases کا gate کام کرتا ہے اور client کا paragraph لکھا گیا | 20 |
| کل · پاس 60 | 100 |
Hand in your lab
Create a free BvLogic ID to hand in your lab, get it marked, and have it on your certificate.
Create your BvLogic IDAlready have one? Sign in and this course will be added to it.