Skip to content
S/N
Selected work
11 — AI & Applied Technology

Every number cited to its page. The reviewer decides.

Type
technical
Role

Designed and built the whole system, the AWS infrastructure as code, the evaluation and the walkthrough film

Context
Procurement teams compare bids that describe the same scope in different ways, with hidden exclusions, VAT mismatches and totals that do not add up. A reviewer needs every extracted number tied to its page, and needs to be the one who decides.

01The brief

Fictional bids for a bus depot maintenance package go in as PDFs. Facts come out with a page citation each, are compared on the same scope, corrected by a reviewer with an audit trail, and exported as a brief. Supplier communications and award decisions stay with the human reviewer.

Procurement teams compare bids that describe the same scope in different ways, with hidden exclusions, VAT mismatches and totals that do not add up. A reviewer needs every extracted number tied to its page, and needs to be the one who decides.

A FastAPI and LangChain backend with a Next.js front end. Extraction uses structured output and citation checks against the PDF text. The same container image runs on AWS Lambda behind API Gateway, with state in S3, and on EC2 as a second CDK stack. The LLM provider switches from local Ollama to Amazon Bedrock.

Challenges

  • Every extracted value has to be checkable, so a wrong page or a made-up quote must be caught, not shown
  • Bid documents can contain instructions aimed at the model, and the first version of the Q&A obeyed one
  • Serverless has limits: a 30 second API timeout, no local disk, and no hourly-billed services allowed in the budget

02Approach

My role

  • Designed and built the whole system, the AWS infrastructure as code, the evaluation and the walkthrough film

Approach

  • LangChain chains with structured output, then verbatim and fuzzy citation checks, page correction and Decimal arithmetic checks on totals and VAT
  • Prompt-injection defence: flagged sentences are redacted before embedding and rejected as evidence
  • AWS CDK in TypeScript: Lambda container image on ECR (arm64) behind API Gateway, S3 state, IAM, CloudWatch and a $5 AWS Budgets alarm. One command deploys, one tears down
  • The same image on an EC2 t4g.small with SSM and no SSH keys, as a second stack to compare cost, cold starts and limits
  • Evaluation and CI: labelled-set scripts, 48 pytest tests with the model mocked, a Playwright end-to-end test and GitHub Actions
Lambda first, EC2 to compare
Lambda costs about nothing when idle and scales per request. EC2 has no cold starts and no 30 second limit but is always on. Both are deployed from the same image so the trade-off is measured, not guessed.
No hourly-billed services
No NAT gateway, RDS, OpenSearch or load balancer. State is a SQLite snapshot in S3 and the vector store is built in memory, which keeps the bill near zero.
A citation or it does not count
A value whose quote cannot be found on the cited page is marked unverified and needs a reviewer. The one recurring miss in testing was caught this way.
Bedrock behind a switch
One setting moves the model from local Ollama to Amazon Bedrock without touching the pipeline. The CloudFront and Bedrock parts are written in CDK and wait on AWS account verification.

03Results

  • 97.8%

    Field accuracy

  • 100%

    Citation validity

  • 18 of 18

    Seeded issues caught

  • 48

    Automated tests

  • 97.8% field accuracy (132 of 135) and 100% citation validity on a labelled synthetic set, 18 of 18 seeded issues caught, no false alarms
  • The injected instruction in one bid never changed an extracted value across all 9 runs
  • Live on AWS Lambda, with a 4 minute narrated walkthrough covering the app, Lambda and EC2, LangChain, evaluation and CI

04Honest limits

  • An independent portfolio project. Not commissioned, endorsed or used by Dubai RTA. All suppliers, bids and criteria are fictional.
  • The labelled set is 3 bids by 15 fields, written by the same author as the prompts, with clean text PDFs. The numbers do not predict accuracy on real, messy bids.
  • The live deployment uses precomputed results. Bedrock and CloudFront are written but not yet deployed.
  • State is a single SQLite file in S3 with one concurrent Lambda, which suits one reviewer and not a team.
  • The retrieval Q&A is less reliable than the comparison matrix (10 of 12 correct citations), so unverified quotes are labelled.
  • AWS Lambda
  • API Gateway
  • S3
  • ECR
  • EC2
  • AWS CDK
  • IAM
  • CloudWatch
  • Amazon Bedrock
  • LangChain
  • FastAPI
  • Next.js
  • TypeScript
  • Docker
  • Playwright
  • GitHub Actions