AI Product Prototyping: A Layered Approach from Interface to Model
This guide explains how to split an AI product into an interface layer, a service layer, and a model layer. It covers prototyping user tasks and interface states first, defining service contracts before implementation, and choosing between prompting, fine-tuning, and knowledge distillation. It also includes compliance boundaries and a pre-release checklist.
1. A Layered Approach: Define Boundaries First, Then Implementation
A user-facing AI product typically consists of three layers. The interface layer handles how users enter content and view results. The service layer handles request routing, authentication, state management, and result assembly. The model layer interprets input and generates output. The layers connect through explicit interface contracts.
The main benefit of this separation is that each layer can evolve independently. A UI redesign should not require retraining the model, and switching model versions should not force a frontend rewrite.
The recommended order is to build an interface prototype first to validate interaction paths, then define service interfaces and fix data structures, and finally integrate or train the model. This order surfaces requirement problems early. It also avoids spending heavily on model compute only to discover that the user flow does not work.
2. Interface Layer: A Prototype Centered on User Tasks
Interface design should start from user tasks, not page styling. Write out the steps for three to five core tasks, such as “upload a document, ask a question, view an answer with sources, and export the result.” Each step maps to an interface state. The conditions for switching between states must be defined in advance.
In practice:
- Establish design tokens (colors, font sizes, spacing, corner radii) to keep the visual style consistent and reduce later rework.
- Split chat bubbles, result cards, input boxes, and similar elements into standalone components. Components receive data through props and do not call APIs directly.
- For streaming output, the interface must handle loading, token-by-token rendering, user interruption, and retry after failure.
The type definitions below show a basic state model for chat messages:
type ChatStatus = "idle" | "submitting" | "streaming" | "done" | "error";interface ChatMessage {id: string;role: "user" | "assistant";content: string;status: ChatStatus;createdAt: number;}
Modeling status explicitly makes interface logic easier to test. It also helps prevent common problems, such as a button that spins indefinitely.
3. Service Layer: Interface Contracts First
The service layer translates between the interface and the model. Define interfaces before implementation. Use a documented interface description file to fix request and response structures, so frontend and backend teams can develop in parallel without blocking each other.
The service layer needs to focus on four areas.
- Authentication and quotas. Bind each request to a user or tenant identity. Limit request rate and concurrency per identity to prevent any single user from exhausting resources.
- Streaming. For long text generation, use server push or chunked transfer. Users can read while the text is still being generated, which noticeably reduces perceived waiting time.
- Error semantics. Distinguish parameter errors, quota limits, model timeouts, and content safety blocks. Return messages that users can understand.
- Observability. Log latency, input and output length, and error codes for each request. These logs help diagnose cost and quality issues.
The example request body below is for illustration only. Field names are not a specification.
{"session_id": "s_20261124_001","message": "Summarize the payment terms in this contract","options": {"stream": true,"max_tokens": 1024}}
The server must store the model access key in a key management service or in environment variables. It must never be written into frontend code or version control.
4. Model Layer: Capability Building and Knowledge Distillation
The goal of the model layer is to make a given task perform reliably at an acceptable cost. There are three common approaches.
The first is to call a general-purpose model directly and use prompts to constrain the output format and role. This is the fastest way to start, and it suits validating requirements.
The second is to fine-tune on your own data. Consider fine-tuning when prompts cannot reliably meet format or domain terminology requirements.
The third is knowledge distillation. A stronger teacher model generates high-quality samples, and those samples train a smaller, lower-latency student model. This approach suits tasks with clear boundaries and high call volume.
The basic distillation process is as follows.
- Define the task and the evaluation set. Collect real or anonymized input samples, and have people annotate reference answers or scoring rules.
- Generate candidate outputs. Run the teacher model on the samples and keep the results that pass scoring.
- Clean and deduplicate. Filter out low-quality samples, duplicates, and samples that contain sensitive information.
- Train the student model. Choose an open-source base model whose license allows commercial use, or start from an in-house model.
- Run comparative evaluation. On a held-out set, compare accuracy, latency, and cost per request to decide whether to deploy.
Illustrative code:
def distill(teacher, student, prompts, judge, threshold=0.8):dataset = []for prompt in prompts:answer = teacher.generate(prompt)if judge.score(prompt, answer) >= threshold:dataset.append({"input": prompt, "output": answer})dataset = dedupe(filter_sensitive(dataset))student.finetune(dataset)return student
Before using a teacher model to generate training data, confirm that its terms of service and license permit this use.
Beyond the model itself, instruction templates, the list of callable tools, and output format constraints are part of the product’s capabilities. Version-control these configurations. Include them in regression tests together with model versions, so results stay reproducible after any change.
5. Boundaries: What Should Not Be Done
Technical choices must be based on compliance. Avoid the following practices.
- Copying a third-party product’s interface assets, copy, icons, or page structure. Design should start from your own users’ needs. You can reference general interaction guidelines, but you should not replicate a specific product.
- Scraping third-party APIs without authorization, cracking signatures, or bypassing access restrictions. These practices violate terms of service and may create legal risk.
- Training your own model on output data whose terms of service prohibit training use.
- Including personal information in training data without authorization or anonymization.
Bringing compliance work into the process early reduces rework costs later.
6. Implementation Checklist
- Core tasks and interface states are documented
- Interface contracts are reviewed and under version control
- Keys are stored in a key management service and do not appear in frontend code
- The evaluation set covers major scenarios and typical failure cases
- Licenses for training data and base models have been confirmed item by item
- Regression tests are completed after any change to model versions or prompt configurations
