Objective & prerequisites
Enforce types, fields and failure behavior while keeping factual checks separate. Prerequisites: Python functions, JSON, lists and the existing API/testing foundations. Extract the full kit and open a terminal in applied-ai-kit. The core lab uses Python 3.10+ with no third-party dependencies or network. Actual new-text semantic inference is a separate optional local setup, tested on Python 3.12/macOS arm64. All CedarLab policies, invoices and review cases are fictional teaching material; they are not DataCareerHub service terms. No payment, registration, live chatbot or visitor-data collection is activated. These free companions do not change course progress or protected access.
python3 lab.py
python3 -m unittest discover -s tests -vUnderstand the concept
A prompt requesting JSON is not a reliable application boundary. Parse a bounded response, reject repeated keys and unexpected fields, then validate exact types, formats and bounds. Python bool is an integer subtype, so money uses an exact int check. Schema-valid values may still be false: a model can return 125400 cents in perfectly valid JSON even though the source says 12540. The answer envelope separately requires answer, citations and abstain. An abstention must have an empty answer and citation list. Citation IDs must name current eligible documents; their presence still does not establish support. A provider-contract exercise uses a local fixture function only, and refuses external mode. It is not an active hosted adapter or measured LLM extraction.
Worked example
validate_invoice accepts C-001/EUR/125400 structurally, illustrating a wrong-but-valid amount. Comparing it to I1’s known source result reveals the mismatch. validate_answer accepts the incorrect thirty-day claim with D1 because its role is structural validation, not entailment. The factual-review lesson must then reject that interpretation. A duplicate JSON key fails before schema validation. The code does not automatically repair malformed responses or repeatedly retry until an invented answer appears.
from lab import validate_invoice,extract_invoice,load
wrong=validate_invoice({"invoice_id":"C-001","currency":"EUR","total_cents":125400})
assert wrong!=extract_invoice(load("invoices.json")[0]["text"])Try it yourself
Read extraction-prompt-template.txt and predict a source-supported object for I1 and null for ambiguous I3; these are expected answers, not measured LLM outputs. Create three local candidate strings: correct invoice, wrong-but-schema-valid amount and boolean money. Predict parsing, schema and source-agreement outcomes separately. Use provider_contract.py with a local fixture function, then attempt allow_external=True and confirm refusal. Do not supply real personal or employer records. Write your prediction, inspect the source and record actual results. Keep a copy of the original fixtures before making changes.
Worked solution
The correct candidate passes structure and source comparison; the tenfold amount passes structure but fails comparison; True fails exact integer validation. External mode raises ValueError before calling the supplied function. A future provider would need an explicit transmission/privacy/cost contract and a separately tested adapter. No provider key, live response, token bill or model quality is claimed by the fixture callback.
Knowledge check
If a JSON schema validates a number, has the application verified that number against the document?
Check and explain
No. Type/shape validation is necessary but source agreement is a separate obligation.
Evidence, mistakes & handover
Record the executed mode: actual local encoder, saved-vector replay, deterministic extraction or human factual review. They establish different things. Keep model/version, source hashes, commands, expected outcomes, failures and limitations with your work. Never turn a schema pass, cosine score or quotation into a claim of proven truth. The download contains a worksheet, independent controls, worked solutions, a factual-review rubric, privacy/cost contract and mini-project checklist. Credit the supplied starting point and describe your own contribution.
Authoritative reference
— official source for the underlying mechanism. Teaching prose and CedarLab cases are original. Model/runtime compatibility, licensing and operating limits require review for any later deployment; this course does not activate a production AI service.
Try the activity before reading its reference. Keep your sources, commands and assumptions with your work. Companion activities are unsaved self-practice and do not award a certificate or change lesson progress.