Module 13 Activity
Scenario
Put the model behind an interface so the service is testable and the vendor is replaceable.
What you build
A model client behind one interface, validated output, cost in the response, and pre-checks that refuse before spending.
Steps
- Define the model call as an interface and provide a real and a fake implementation.
- Override it in tests so the whole suite runs offline, and make the real one fail loudly without configuration.
- Validate the model's output against a schema before returning it, and decide the status when it fails.
- Return cost, latency and versions in a
metablock. - Implement pre-checks - empty input, over-length, sensitive content, budget - that refuse before any spend.
- Confirm sensitive input never reaches the provider or your logs.
Evidence to hand in
- The interface with both implementations.
- The offline suite, and the loud failure without configuration.
- The output validation and its failure status.
- The meta block.
- The pre-checks with what each refuses.
Review checklist
- The service depends on a shape, not on the vendor.
- The real client fails loudly rather than falling back to a fake.
- Model output is validated before it is returned.
- Cost and versions are in a separable meta block.
- The budget check runs before the call, using an estimate.
