<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdus samad khan</title>
    <description>The latest articles on DEV Community by Abdus samad khan (@abdus_samadkhan_66484950).</description>
    <link>https://dev.to/abdus_samadkhan_66484950</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4255993%2F5ebc7a93-ddd7-4228-b934-2347ae787c0a.png</url>
      <title>DEV Community: Abdus samad khan</title>
      <link>https://dev.to/abdus_samadkhan_66484950</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdus_samadkhan_66484950"/>
    <language>en</language>
    <item>
      <title>Building an AI-Powered Feature in a Web App: A Practical Architecture Walkthrough</title>
      <dc:creator>Abdus samad khan</dc:creator>
      <pubDate>Fri, 20 Nov 2026 15:51:40 +0000</pubDate>
      <link>https://dev.to/abdus_samadkhan_66484950/building-an-ai-powered-feature-in-a-web-app-a-practical-architecture-walkthrough-3dmf</link>
      <guid>https://dev.to/abdus_samadkhan_66484950/building-an-ai-powered-feature-in-a-web-app-a-practical-architecture-walkthrough-3dmf</guid>
      <description>&lt;p&gt;AI features are becoming a common part of modern web applications. From document summarization and intelligent search to customer support assistants, developers are finding new ways to integrate large language models (LLMs) into existing products.&lt;/p&gt;

&lt;p&gt;However, adding an AI feature is not simply a matter of connecting an API and displaying its response.&lt;/p&gt;

&lt;p&gt;A reliable implementation requires several components to work together including the frontend, backend, model integration, input validation, error handling, security controls, and monitoring.&lt;/p&gt;

&lt;p&gt;This guide walks through a practical architecture for adding an AI-powered feature to a web application using a Node.js backend. The example focuses on a document summarization feature, but the same architecture can be adapted for chatbots, content assistants, and other AI-powered functionality.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Start With a Clearly Defined Use Case
&lt;/h2&gt;

&lt;p&gt;Before choosing an AI model or framework, identify the problem the feature should solve.&lt;br&gt;
Consider a SaaS application that allows users to manage business documents. Users might spend considerable time reading long documents to identify important information.&lt;/p&gt;

&lt;p&gt;An AI-powered summarization feature could help by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extracting the main points from a document.&lt;/li&gt;
&lt;li&gt;Identifying important decisions and action items.&lt;/li&gt;
&lt;li&gt;Producing a shorter, structured summary.&lt;/li&gt;
&lt;li&gt;Allowing users to review the result before saving it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The important distinction is that AI should solve a specific user problem rather than exist simply because the technology is available.&lt;/p&gt;

&lt;p&gt;For this example, the expected workflow is straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A user selects a document.&lt;/li&gt;
&lt;li&gt;The frontend sends the document text to the backend.&lt;/li&gt;
&lt;li&gt;The backend validates the request.&lt;/li&gt;
&lt;li&gt;The backend sends the relevant content to an LLM.&lt;/li&gt;
&lt;li&gt;The response is checked and returned in a predictable format.&lt;/li&gt;
&lt;li&gt;The frontend displays the summary.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  2. Understand the Application Architecture
&lt;/h2&gt;

&lt;p&gt;A practical architecture separates responsibilities between the frontend, backend, and AI integration layer.&lt;/p&gt;

&lt;p&gt;The frontend handles user interaction, while the backend manages authentication, validation, permissions, and communication with the AI provider.&lt;/p&gt;

&lt;p&gt;A simplified architecture looks like this:&lt;br&gt;
text&lt;/p&gt;

&lt;p&gt;A simplified architecture looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    A[User] --&amp;gt; B[React / Next.js UI]
    B --&amp;gt; C[API Request]
    C --&amp;gt; D[Node.js Backend]

    D --&amp;gt; E[Authentication]
    D --&amp;gt; F[Input Validation]
    D --&amp;gt; G[Rate Limiting]

    E --&amp;gt; H[AI Service]
    F --&amp;gt; H
    G --&amp;gt; H

    H --&amp;gt; I[LLM Provider]
    I --&amp;gt; J[Response Validation]
    J --&amp;gt; K[Frontend Result]

    style A fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
    style H fill:#ede9fe,stroke:#7c3aed,color:#4c1d95
    style I fill:#dcfce7,stroke:#16a34a,color:#14532d
    style K fill:#fef3c7,stroke:#d97706,color:#78350f&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This separation is important because the frontend should never communicate directly with an AI provider using a private API key.&lt;/p&gt;

&lt;p&gt;The backend acts as a controlled gateway between the application and the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Build the Backend API Endpoint
&lt;/h2&gt;

&lt;p&gt;The first implementation step is creating an endpoint that accepts document content and returns a summary.&lt;/p&gt;

&lt;p&gt;For a Node.js application, Express can handle the API request.&lt;/p&gt;

&lt;p&gt;Here is a simplified example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;javascript&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"zod"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;summarizeDocument&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./ai-service.js"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"100kb"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;summarySchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/api/summarize"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Validate incoming data&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;summarySchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;safeParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Invalid document content"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// Generate the summary&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;summarizeDocument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;summary&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Summarization failed:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Unable to summarize the document"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This endpoint performs three basic operations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validates the incoming document.&lt;/li&gt;
&lt;li&gt;Passes valid content to the AI service.&lt;/li&gt;
&lt;li&gt;Returns a predictable response to the frontend.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In production, authentication, authorization, rate limiting, and request tracing should also be applied before processing the request.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Keep AI Integration Separate
&lt;/h2&gt;

&lt;p&gt;One common architectural mistake is placing model-specific logic directly inside API routes.&lt;/p&gt;

&lt;p&gt;This makes the application harder to maintain when changing providers, adjusting prompts, or introducing additional AI features.&lt;/p&gt;

&lt;p&gt;A separate AI service provides a cleaner structure.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;javascript&lt;/span&gt;
&lt;span class="c1"&gt;// ai-service.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;summarizeDocument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`
    Summarize the following document.
    Return:
    - Main points
    - Important decisions
    - Action items
    Document:
    ${document}
  `&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// Call the configured LLM provider here.&lt;/span&gt;
  &lt;span class="c1"&gt;// Keep provider credentials on the server.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;modelClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;validateSummary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;modelClient&lt;/code&gt; and &lt;code&gt;validateSummary&lt;/code&gt; represent application-specific provider and validation modules that need to be implemented.&lt;/p&gt;

&lt;p&gt;The benefit is that the API route does not need to know how the underlying model works.&lt;/p&gt;

&lt;p&gt;The same service can later support multiple models or different AI tasks without rewriting the entire backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Validate AI Responses Before Returning Them
&lt;/h2&gt;

&lt;p&gt;An AI model does not automatically guarantee that its response follows the expected structure.&lt;/p&gt;

&lt;p&gt;For example, the application might expect three fields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mainPoints"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"First important point"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Second important point"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"decisions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"Approved the proposed timeline"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"actionItems"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"Prepare the implementation plan"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, a model might return incomplete information, unexpected formatting, or additional text.&lt;/p&gt;

&lt;p&gt;This is why response validation matters.&lt;/p&gt;

&lt;p&gt;A schema validation library such as Zod can help enforce the expected structure:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;javascript&lt;br&gt;
import { z } from "zod";&lt;br&gt;
const summaryResponseSchema = z.object({&lt;br&gt;
  mainPoints: z.array(z.string()),&lt;br&gt;
  decisions: z.array(z.string()),&lt;br&gt;
  actionItems: z.array(z.string())&lt;br&gt;
});&lt;br&gt;
export function validateSummary(response) {&lt;br&gt;
  return summaryResponseSchema.parse(response);&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
If the model returns an invalid structure, the application can handle the failure instead of displaying unexpected data.&lt;/p&gt;

&lt;p&gt;For more reliable results, structured output capabilities provided by the selected model can also be used.&lt;/p&gt;
&lt;h2&gt;
  
  
  6. Handle Security, Permissions, and API Limits
&lt;/h2&gt;

&lt;p&gt;AI integration introduces additional security considerations.&lt;/p&gt;

&lt;p&gt;A few important practices include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protect API credentials&lt;/strong&gt;&lt;br&gt;
Store provider API keys in server-side environment variables. Never expose private credentials in frontend JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Validate user permissions&lt;/strong&gt;&lt;br&gt;
Users should only be able to submit documents they are authorized to access. Authentication alone does not establish permission to access every document.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Apply rate limits&lt;/strong&gt;&lt;br&gt;
Without rate limiting, a single user could generate excessive API requests and increase infrastructure costs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Control document size&lt;/strong&gt;&lt;br&gt;
Large documents can increase token usage, latency, and processing costs. Set appropriate input limits and use document chunking when necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protect sensitive information&lt;/strong&gt;&lt;br&gt;
Consider whether documents contain personal, financial, or confidential information. Review the model provider's data handling and retention policies before sending such information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Treat model output as untrusted&lt;/strong&gt;&lt;br&gt;
AI-generated content should not automatically be executed as code, SQL, or privileged application commands.&lt;/p&gt;

&lt;p&gt;These controls should be implemented in the backend rather than relying on frontend restrictions.&lt;/p&gt;
&lt;h2&gt;
  
  
  7. Test the Complete Workflow
&lt;/h2&gt;

&lt;p&gt;A successful API response does not necessarily mean the feature is production-ready.&lt;/p&gt;

&lt;p&gt;Testing should cover different scenarios to ensure the application behaves correctly under both normal and unexpected conditions.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    A[Start Testing] --&amp;gt; B{Test Scenario}

    B --&amp;gt;|Valid document| C[Summary Generated]
    B --&amp;gt;|Empty document| D[Validation Error]
    B --&amp;gt;|Oversized document| E[Request Rejected]
    B --&amp;gt;|Invalid model response| F[Response Validation Fails]
    B --&amp;gt;|Provider timeout| G[Controlled Error Returned]
    B --&amp;gt;|Unauthorized request| H[Access Denied]
    B --&amp;gt;|Excessive requests| I[Rate Limit Applied]

    C --&amp;gt; J[Verify Expected Behavior]
    D --&amp;gt; J
    E --&amp;gt; J
    F --&amp;gt; J
    G --&amp;gt; J
    H --&amp;gt; J
    I --&amp;gt; J

    J --&amp;gt; K[Application Ready for Further Testing]

    style A fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
    style C fill:#dcfce7,stroke:#16a34a,color:#14532d
    style J fill:#ede9fe,stroke:#7c3aed,color:#4c1d95
    style K fill:#fef3c7,stroke:#d97706,color:#78350f&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;It is also important to monitor response times, model usage, API costs, and error rates.&lt;/p&gt;

&lt;p&gt;For AI features, quality evaluation deserves additional attention. A technically valid response can still be inaccurate or omit important information.&lt;/p&gt;

&lt;p&gt;A small evaluation dataset containing representative documents and expected outcomes can help detect quality regressions when prompts or models change.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Prepare the Feature for Production
&lt;/h2&gt;

&lt;p&gt;Once the basic workflow works, several improvements can make it more dependable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add asynchronous processing for large documents.&lt;/li&gt;
&lt;li&gt;Use background jobs when requests take too long.&lt;/li&gt;
&lt;li&gt;Cache results when the underlying document and processing configuration have not changed.&lt;/li&gt;
&lt;li&gt;Track model usage and estimated costs.&lt;/li&gt;
&lt;li&gt;Add retries with appropriate limits for temporary provider failures.&lt;/li&gt;
&lt;li&gt;Provide users with clear feedback when processing takes longer than expected.&lt;/li&gt;
&lt;li&gt;Allow users to review and edit generated summaries.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These improvements should be introduced according to the application's requirements rather than adding unnecessary infrastructure from the beginning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Building an AI-powered feature requires more than connecting an application to an LLM.&lt;/p&gt;

&lt;p&gt;The real engineering work involves creating a reliable system around the model: validating inputs, protecting data, managing permissions, handling failures, checking outputs, and monitoring performance.&lt;/p&gt;

&lt;p&gt;Starting with a small, clearly defined use case makes it easier to understand these requirements before expanding the feature.&lt;/p&gt;

&lt;p&gt;For developers building AI-powered web applications, the goal should not simply be to make AI work in a demonstration. It should be to make the feature useful, secure, maintainable, and dependable for real users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Further reading:&lt;/strong&gt; Developers exploring AI integration and application architecture can also find more information in &lt;a href="https://cipherslab.com/generative-ai-development/" rel="noopener noreferrer"&gt;CiphersLab's generative AI development resource&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Author: Abdus Samad&lt;br&gt;
Focus: Full-stack development, AI-powered applications, and SaaS engineering.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
