A model produces content; an application completes a job
A generative model accepts a request and returns an output. A useful application must also decide what input is allowed, which evidence belongs in the request, what output shape is acceptable, how claims are checked, what the user sees, and what happens when any step fails. In short: model ≠ application.
We will use a meeting-summary application throughout. Its narrow job is to turn an approved transcript into decisions and action items that a participant can review. A simple baseline might be keyword search plus copied sentences. The generator should be kept only if the evaluated workflow improves on that baseline without creating unacceptable unsupported actions.
Building Generative AI Applications in Simple Words
Calling a model API from a Jupyter notebook is a demonstration; building a production application is software engineering. A real application surrounds the raw model with safety airlocks: caching identical requests to slash cloud bills, validating input schemas, grounding drafts in trusted enterprise databases (RAG), and treating raw model output as an unverified draft that must pass strict Pydantic JSON parsing before reaching any human user!
Input Gate & Cache
Sanitizes prompts and returns cache hits in 15ms
Grounding / Context
Injects verified facts, documentation, or tools
Structured Gen
Enforces rigid JSON schema adherence
Output Validation
Verifies citations, evidence, and business constraints
Define success before designing prompts
“Write a good summary” cannot be tested consistently. For this hypothetical application, the team chooses two release criteria: every response must pass the output schema, and at least 90% of action items in a fixed evaluation set must contain evidence copied from the transcript. The 100% schema rule and 90% evidence threshold are developer-chosen acceptance limits; the observed rates will be measured later. They are not facts learned by the model.
Instructions, context, retrieval, and tools have different jobs
| Component | Purpose | Meeting-summary example | Do not assume |
|---|---|---|---|
| Instructions / prompt | Describe the task, boundaries, and format. | “Return decisions and supported action items only.” | Wording alone guarantees truth. |
| Context | Supply information the model may use now. | The authorized meeting transcript. | More context is always safer or better. |
| Retrieval | Find external evidence when the task needs it. | Fetch a named project glossary, if required. | Every generation app needs a full RAG system. |
| Tool | Perform a calculation or authorized action. | Create a calendar draft only after approval. | Generated text should execute actions directly. |
Figure 1 — The model is one component inside the application
Deterministic application logic controls what reaches the model and what becomes visible to the user. Invalid or uncertain outputs leave the main path through retry, fallback, or human review.
A nine-stage application architecture moves from user input to input validation, context or evidence assembly, request construction, generative model, structured output, schema validation, business and evidence validation, and user-visible result. The model is visually isolated inside a model boundary, while surrounding stages are application logic. Failed validation branches to bounded retry, safe fallback, or human review. Evaluation and feedback logging observe the result without requiring raw private content.
Structure first, then validate meaning
A structured output schema can require a list of decisions and action-item objects with owner, task, and evidence fields. Schema validation catches missing fields and wrong types. It does not prove that “Maya” was actually assigned the task. A deterministic evidence rule can require the evidence string to occur in the transcript; human review can handle ambiguous or high-impact cases.
Deterministic post-processing is useful for normalizing dates, trimming whitespace, applying permission rules, and rejecting values outside known limits. It should not silently rewrite uncertain model claims into something that only looks verified.
Figure 2 — Parsing is only the first validation gate
The valid meeting-summary draft has the required types and transcript evidence. The invalid draft fails both structure and evidence checks, so it cannot become a user result.
Model output enters parse and validate, then branches. The valid miniature output contains a decisions list and an action item for Maya with evidence copied from the transcript; it passes schema and business evidence rules and becomes a usable reviewable result. The invalid miniature output uses a string where decisions should be a list and says Sam should book a venue using evidence absent from the transcript; it is rejected and routed to bounded retry, fallback, or human review.
Model output · untrusted draft
Parse → schema → evidence rules
VALID
decisions: [pilot]
owner: Maya
task: revised budget
evidence: in transcript
schema ✓ evidence ✓ → usable
INVALID
decisions: “pilot”
owner: Sam
task: book venue
evidence: absent
reject → retry / fallback / review
Valid JSON can still contain an unsupported claim.
Validate a generated summary with ordinary Python
This code is genuinely runnable with Python 3 and no extra package. The valid object has the expected types and exact transcript evidence, so it prints an empty error list. The invalid object uses a string instead of a decisions list and cites evidence absent from the transcript, so both failures are reported.
# Python 3 — deterministic validation; no model or external package is used.
transcript = "Maya will send the revised budget by Friday. The team approved a two-week pilot."
valid_output = {
"decisions": ["The team approved a two-week pilot."],
"action_items": [{
"owner": "Maya",
"task": "send the revised budget",
"evidence": "Maya will send the revised budget by Friday.",
}],
}
invalid_output = {
"decisions": "A two-week pilot", # should be a list
"action_items": [{"owner": "Sam", "task": "book a venue", "evidence": "not in transcript"}],
}
def validate_summary(value, source_text):
errors = []
if not isinstance(value, dict):
return ["output must be an object"]
if not isinstance(value.get("decisions"), list):
errors.append("decisions must be a list")
items = value.get("action_items")
if not isinstance(items, list):
errors.append("action_items must be a list")
return errors
for index, item in enumerate(items):
required = {"owner", "task", "evidence"}
if not isinstance(item, dict) or not required.issubset(item):
errors.append(f"action_items[{index}] is missing required fields")
elif item["evidence"] not in source_text:
errors.append(f"action_items[{index}] evidence is not in the transcript")
return errors
print("valid:", validate_summary(valid_output, transcript))
print("invalid:", validate_summary(invalid_output, transcript))Where a real model call would fit
This is architecture pseudocode, not runnable code: function names and generation APIs depend on the selected stack. Its purpose is to show that the model output remains a draft until deterministic checks pass.
# Conceptual pseudocode — adapt to the chosen model/provider.
validated_input = validate_input(user_transcript)
request = build_request(instructions, validated_input, output_schema)
draft = model.generate_structured(request)
errors = validate_schema_and_evidence(draft, validated_input)
result = draft if not errors else safe_fallback(errors)
record_evaluation_event(case_id, errors) # exclude unnecessary private textEnd-to-End Production Latency Breakdown (Milliseconds)
Comparing total request lifecycles across remote providers, semantic caching, self-hosted vLLM, and local inference.
Plan failure behavior before the happy path ships
| Failure class | Example | Application response | Evaluation signal |
|---|---|---|---|
| Invalid input | Empty, oversized, or unauthorized transcript | Reject before generation with a clear correction | Input-rejection reason |
| Invalid structure | Missing action_items list | One bounded repair attempt or safe failure | Schema-failure rate by model/version |
| Unsupported claim | Action has no transcript evidence | Remove, flag, or send for human review | Evidence-failure tag and case |
| Ambiguous high impact | Unclear owner for a contractual action | Require participant confirmation | Escalation and correction outcome |
Store reusable cases and expected properties in an evaluation harness. Run it when instructions, context logic, model versions, or schemas change. Log case identifiers, failure categories, latency, and user corrections while minimizing private transcript content. That turns vague complaints into reproducible engineering work.
Keep the lesson boundary clear
This lesson owns workflow and application logic: validation, context, request design, structure, evidence rules, feedback, and fallbacks. The next lesson owns serving and infrastructure: secrets, provider abstraction, traffic, scaling, rollouts, and production observability.
Summary / Key Takeaways
- A generative model returns content; an application must also control inputs, evidence, output shape, validation, user experience, and failure behavior.
- Begin with a narrow job, measurable acceptance limits, and a simple non-generative baseline before keeping a model in the workflow.
- Instructions define the task, context supplies current evidence, retrieval finds external evidence, and tools perform authorized calculations or actions.
- A schema can verify fields and types, but separate evidence and business rules are needed to check whether the content is supported and allowed.
- Treat every model response as an untrusted draft until deterministic structure and meaning checks pass.
- Reject invalid inputs early, bound repair attempts, and route unsupported or high-impact ambiguous cases to a person.
- Keep a failure-labelled evaluation set and rerun it whenever instructions, context logic, models, or schemas change.