Project snapshot
What I owned
I worked across the customer and engineering boundary rather than treating the new request as a prompt-only change.
The system before the change
The service generated English questions from a passage using LangChain, retrieval-augmented generation and GPT. It was already in use, but quality had begun to drift.
- Duplicate questions appeared in the output.
- Incorrect options were sometimes unrelated to the passage.
- Few-shot retrieval selected examples that did not match the intended question type or student level.
- Failures were not consistently caught before reaching the final output.
These were not isolated prompt defects. Retrieval, output structure and validation all contributed to the final quality.
The new customer requirement
The customer planned to embed the tool into its own service, where a one-passage, two-question format was a core product requirement.
“Generate two related questions from the same passage.”
Customer requirement
The request sounded like an additional output option, but the system was organised around one independent item per generation pass. Each item managed its own context, and the pipeline had no shared passage object that two questions could reliably reference.
Adding another prompt call would create two questions, but it would not guarantee that they shared the same passage context or formed a valid linked set.
Scoping the request with the customer
I divided the request into two groups and explained the difference directly.
Could be improved immediately
- Retrieval selection and few-shot quality
- Prompt and output consistency
- Item formatting and validation rules
- Existing single-item quality defects
Required architectural change
- Shared passage context across multiple questions
- Separation of generation stages
- Passage-level token management
- Cache behaviour for linked outputs
A limitation paired with a date
I told the customer that the current architecture could not support the complete requirement reliably, then committed to delivering the structural changes within three weeks. The conversation established a clear boundary without ending at “no”.
Key decisions
01Separate immediate quality fixes from structural work
Treating every issue as one large rewrite would have made progress difficult to explain and verify. I separated retrieval, prompt and validation improvements from the architecture required for linked questions.
This gave the customer a clear view of what could improve now and what depended on the redesign.
02Make the passage a first-class unit of the pipeline
The old system centred each generation pass on one question. The new architecture centred the workflow on a shared passage context that could coordinate multiple questions.
This allowed linked items to use the same source context while preserving their individual generation and validation steps.
03Improve few-shot selection by student level and similarity
The retrieval system could select examples that were semantically similar but educationally inappropriate. I retuned the vector values by school level and rewrote similarity selection so few-shot examples matched both the content and the intended learner.
This addressed a failure source upstream of the prompt instead of trying to repair every bad example after generation.
04Standardise item structure and add multi-stage validation
I standardised the representation of generated items and introduced multiple validation stages. This made duplicate, relevance and structure failures easier to detect before the final response.
Validation became part of the generation system rather than a final manual check.
05Measure behaviour across repeated GPT runs
Individual examples were too variable to support architecture decisions. I ran approximately 800 GPT API tests across the changed pipeline and used repeated results to refine prompts, retrieval and validation.
Architecture: before and after
Stage names are generic here. Actual pipeline component and cache names are withheld until the customer confirms what can be disclosed.
The three weeks
Reproduced the failures
Duplicate items, unrelated distractors, and few-shot examples selected at the wrong level — reproduced rather than reported.
Classified the request
Immediate fixes separated from architecture-dependent requirements, then explained to the customer with a three-week commitment.
Retrieval rebuilt
Vector values retuned by school level; similarity selection rewritten so examples matched content and learner.
Structure and validation
Generated item structure standardised; multi-stage validation added inside the pipeline.
Passage-centred redesign
Shared passage context, separated generation stages, reworked passage-level token management and cache behaviour.
~800 GPT API tests
Repeated runs across the changed pipeline; prompts, retrieval and validation refined from the aggregate, not from single outputs.
Shipped
The linked-question requirement delivered within the committed timeline and deployed to the live service.
Testing and performance
Figures describe the tested generation pipeline after the changes. Exact measurement conditions and the distribution of the ~800 test runs across question types are pending customer confirmation before publication.
Outcome
Measured results
- Generation latency improved from 15 seconds to 8 seconds.
- Failure rate decreased from 5% to 1.5%.
- The previously unsupported linked-question requirement was delivered within three weeks.
- The completed work contributed to a USD 40K annual B2B contract.
Delivery status
- The redesigned pipeline was shipped to the live service.
- The customer requirement was completed within the committed timeline.
Scope of the claim
- Performance figures describe the generation pipeline after the changes, measured internally.
- The re-architecture was implemented by two people; the plan, prompts, retrieval work and testing were mine.
What I learned
Technical honesty was most useful when paired with a delivery path. Dividing the request into “possible now” and “possible after architectural change” let me explain a real limitation without turning it into a dead end for the customer.
The quality problems also reinforced that an LLM output failure may begin before the prompt. Retrieval quality, shared context, structure, validation and caching all shaped the final result.
If I repeated the project, I would add explicit retrieval-quality checks earlier. That would have caught the few-shot mismatch before it became a downstream generation problem.
Diagrams are drawn from the real systems and redrawn here; customer names, data and identifiers are removed.