Engineer Reliable AI Solutions¶
| Category | AI Solutions Engineering |
| Status | โ Completed |
| Repo | nextwork-engineer-reliable-ai-solutions |
| Original NextWork guide | nextwork.ai |
Learning project
Practice work following a NextWork guide, separate from my production projects.
๐ NextWork learning project. This is a practice project I built while working through NextWork's Engineer Reliable AI Solutions guide. It is part of my Learning portfolio and is fully separate from my production projects.
Category: Learning โบ AI Solutions Engineering
Status: โ
Completed
Overview¶
An AI classifier will sometimes be wrong, so reliability comes from what wraps it. The model proposes a priority and team. Policy code forces P1 plus human review for outages, security, and double charges, honors human overrides, and falls back to rules if the provider fails or returns junk. evals.py shows the baseline's policy failures, proves the guarded version has none, and checks resilience to a downgraded model and a provider outage.
Summary¶
The guarded triage API (urgent escalation, human overrides, provider fallback), a two-tier eval suite, and a GitHub Actions merge gate are built. The evals take known policy failures from 3 (baseline) to 0 and pass the model-downgrade and outage scenarios. A live tier runs the same policy check on a real model (local Ollama standing in for Gemini): the raw model has 3 policy failures and the guarded service has 0. The secret mission is done: a failed gate opens a GitHub Issue. I fired one controlled failure on the real repo, the workflow opened issue #1 with the failing case and run link, and I closed it after confirming. Normal pushes still pass.
The checks behind this are in docs/verification.txt.
Skills & tools¶
AI evals, Guardrails, Fallbacks, FastAPI, GitHub Actions, Reliability engineering
What I built¶
triage.py: the guardrail logic with a trace of which rule fired.providers.py: recorded, downgraded, outage, and Ollama providers.evalset.jsonandrecorded_model_answers.json: 7 tickets with expected outcomes and realistic model errors.evals.py: the Tier 1 and Tier 2 gate.api.py: POST /triage..github/workflows/gate.yml: the merge gate.python evals.py --live qwen2.5:3b: Tier 3, the policy check against a real local model, raw and guarded (docs/live-eval.txt).open_issue.py+ theif: failure()step in.github/workflows/gate.yml(secret mission): a failed gate opens one labelledreliability-gateissue with the failing cases, run link, and gate output. A repeat failure comments on that issue instead of opening a duplicate.docs/controlled-failure-run.md: evidence from the live controlled failure (run, steps, issue #1, closed).- Controlled failure: a manual
workflow_dispatchrun withforce_fail(EVAL_FORCE_FAIL=1) adds one mislabelled urgent ticket, so the gate fails on purpose without breaking normal pushes. Tests prove the gate fails, the issue text is right, and the open-then-comment handoff works against a fake GitHub API.
How to run¶
pip install -r requirements.txt
python evals.py
uvicorn api:app
Verification¶
I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.
/workspace/nextwork-portfolio/.venv/bin/python evals.py && /workspace/nextwork-portfolio/.venv/bin/python -m pytest -q -p no:cacheprovider test_service.py
Notes¶
Model/provider substitution: the guide's service calls Gemini. The CI gate replays recorded answers so it needs no credential, and the live tier uses a local model through Ollama. With the guardrails, the 3B model's under-prioritised tickets never become policy failures.
Original project: https://nextwork.ai/projects/8f437714-0223-4f44-8b12-5b717b58a3d8 ยท Part of my NextWork Learning portfolio (hub).
Verification output¶
From docs/verification.txt:
$ /workspace/nextwork-portfolio/.venv/bin/python evals.py && /workspace/nextwork-portfolio/.venv/bin/python -m pytest -q -p no:cacheprovider test_service.py
TIER 1 baseline (no guardrails): 3 policy failures
- urgent_not_escalated | Site is down for everyone in EU, checkout returns 500
- urgent_not_escalated | I was charged twice for my March invoice
- urgent_not_escalated | Possible security issue: someone hacked my account and changed the email
TIER 1 guarded: 0 policy failures
TIER 2 downgraded model: 0 policy failures, decision sources=['model', 'rules']
TIER 2 provider outage: 0 policy failures, decision sources=['rules']
TIER 2 human override honored: True
GATE: PASS
..... [100%]
5 passed in 0.83s
[exit code 0]