Learning objectives
By the end of this module, you should be able to:
- Distinguish a model, an inference service and an AI application.
- Explain why model output is probabilistic and why that changes testing strategy.
- Write an application contract that defines task, allowed data, output, failure handling and evaluation criteria.
A model is a component, not the application
A language model maps context to a probability distribution over possible next tokens. The application around it decides what context is supplied, what tools are exposed, how outputs are validated and what happens when confidence or policy is insufficient.
Treating the model as the entire system hides the controls that make an AI feature dependable: retrieval, schemas, authorization, evaluation, observability and fallback.
Start from the decision or user job
A strong AI requirement names the user, the task, the acceptable evidence and the consequence of a wrong answer. 'Add a chatbot' is not an engineering requirement.
For Atlas Assist, the useful contract is narrower: answer internal support questions using approved documents, cite the supporting passages, and refuse or escalate when the evidence is insufficient.
Probabilistic output changes the test model
Traditional software can often assert one deterministic output for one input. Generative systems may produce multiple acceptable outputs, so tests need criteria such as factual support, schema validity, task completion, policy compliance and latency rather than exact string equality.
Context is a bounded resource
Instructions, conversation history, retrieved evidence and tool results all consume context. More context is not automatically better: irrelevant material raises cost and can distract the model. Context engineering is the deliberate selection, ordering and compression of information needed for the current decision.
- system/developer instructions
- current user request
- retrieved evidence
- tool definitions and results
- conversation state
- response schema and policy
World-class AI engineering is evidence driven
Prompt quality matters, but production quality comes from a loop: specify behaviour, build a representative evaluation set, instrument failures, change one part of the system and measure whether the target behaviour improved.
Worked examples
System boundary
User → application policy → context builder → model → validator → response
↘ tools / retrieval
- The model sits inside a larger control system.
- Most production failures are system failures, not simply 'bad prompts'.
Atlas Assist contract
Task: answer approved support questions
Evidence: approved KB only
Output: answer + source IDs + confidence state
Fail closed: if evidence is insufficient, say so and escalate
Success: grounded, useful, policy-compliant response
- The contract gives later modules something measurable to improve.
Try it · core lab · account-free
Lab 01 — Write an AI application contract
Goal: Turn an ambiguous assistant request into an explicit, testable engineering contract.
Before you start
- No paid API or cloud account is required for the core lab.
- Core labs use Python 3 and local files only.
- Running case: you are engineering 'Atlas Assist', an internal support assistant over a small approved knowledge base with one read-only inventory tool.
- Carry requirements, eval cases, threat assumptions and operational evidence forward across modules instead of starting over.
STEP 1Create the contract
cat > /tmp/atlas-contract.json <<'EOF'
{
"user": "internal support engineer",
"task": "answer approved operational questions",
"allowed_sources": ["kb"],
"must_return": ["answer","source_ids","status"],
"forbidden": ["invented credentials","unsupported claims"],
"fallback": "INSUFFICIENT_EVIDENCE"
}
EOF
STEP 2Validate required fields
python3 - <<'PY2'
import json
x=json.load(open('/tmp/atlas-contract.json'))
required={'user','task','allowed_sources','must_return','forbidden','fallback'}
missing=required-set(x)
assert not missing, missing
assert 'source_ids' in x['must_return']
print('PASS: explicit AI application contract')
PY2
STEP 3Add two failure examples
Write one example where the assistant should answer and one where it must return INSUFFICIENT_EVIDENCE. These become seed evaluation cases later.
Verify
- The contract names the user task, evidence boundary, response fields and fallback.
- Failure behaviour is explicit rather than implied.
Expected outcome
- A machine-readable contract plus two seed cases.
Break / fix · diagnose
- If the requirement says only 'be accurate', replace it with an observable criterion.
- If every question must be answered, the failure contract is unsafe or unrealistic.
Production viewAI teams move faster when model experiments are judged against a stable application contract rather than subjective demos.
Local real-tool practicum · optional but recommended
Optional practicum — inspect a local inference endpoint
Confirm that the model service and application are separate operational surfaces.
Prerequisites
- Ollama installed and reachable on http://127.0.0.1:11434 for the real-tool path.
Resources created
- Only local disposable files/processes used by the practicum.
Cost / risk
- No cloud account required; model downloads consume disk and network bandwidth.
TOOL 1curl -fsS http://127.0.0.1:11434/api/version
TOOL 2curl -fsS http://127.0.0.1:11434/api/tags | python3 -m json.tool | head -80
Verify
- The Ollama service responds independently of any particular prompt or application.
Cleanup
- Remove only the disposable files created for the lab; keep model caches only if you intend to reuse them.
Warnings
- Do not pull a large model just to complete this module; model acquisition belongs in Module 02.
Avoid these traps
Common mistakes
- Defining the product as 'a chatbot'.
- Assuming fluent output is evidence of correctness.
- Treating larger context as automatically better.
- Starting implementation before defining failure behaviour.
Knowledge check
Can you connect the AI behaviour to a system control?
Concept and scenario checks. Reveal the answer only after you commit to a decision.
1Why is an LLM not the complete AI application?
Because policy, context, retrieval, tools, validation, authorization, evaluation and fallback are application responsibilities around the model.
2Why are exact-output assertions often insufficient?
Multiple outputs can be acceptable, so evaluation must test behavioural criteria such as grounding, schema validity and policy compliance.
3What should happen when approved evidence is insufficient?
The application should follow its explicit fallback or escalation contract rather than inventing an answer.
4Scenario: a demo is eloquent but cannot name its evidence source. What is missing?
A grounded application contract and evaluation criterion connecting claims to approved evidence.