<?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>Forem: Aakash Aggarwal</title>
    <description>The latest articles on Forem by Aakash Aggarwal (@aakasha063).</description>
    <link>https://forem.com/aakasha063</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3038939%2Fe312b2b7-8a52-4f49-9461-1b9a5e1c49fb.png</url>
      <title>Forem: Aakash Aggarwal</title>
      <link>https://forem.com/aakasha063</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aakasha063"/>
    <language>en</language>
    <item>
      <title>How to Prevent Hallucinations When Integrating AI Into Your Applications</title>
      <dc:creator>Aakash Aggarwal</dc:creator>
      <pubDate>Wed, 16 Apr 2025 19:03:33 +0000</pubDate>
      <link>https://forem.com/aakasha063/how-to-prevent-hallucinations-when-integrating-ai-into-your-applications-3jkp</link>
      <guid>https://forem.com/aakasha063/how-to-prevent-hallucinations-when-integrating-ai-into-your-applications-3jkp</guid>
      <description>&lt;p&gt;AI has made its way into production applications across industries—from search assistants to medical diagnosis, and even legal document summarisation. But one persistent problem can tank user trust and business credibility: &lt;strong&gt;AI hallucinations&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this post, we’ll break down what hallucinations are, why they happen, and how you can &lt;strong&gt;actively prevent them&lt;/strong&gt; when integrating large language models (LLMs) into your app.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Are AI Hallucinations?
&lt;/h2&gt;

&lt;p&gt;AI hallucinations occur when an LLM generates output that sounds confident and fluent, but is factually &lt;strong&gt;inaccurate, made-up, or misleading&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Albert Einstein was born in 1975 in Canada.”&lt;br&gt;&lt;br&gt;
 Confidently wrong.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For mission-critical apps (healthcare, fintech, legal tech), hallucinations can be dangerous. So, how do we deal with this?&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Do LLMs Hallucinate?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;They &lt;strong&gt;don’t “know”&lt;/strong&gt; facts—they predict the most likely next word.&lt;/li&gt;
&lt;li&gt;They are trained on &lt;strong&gt;incomplete, biased, or outdated data&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;They &lt;strong&gt;fill in gaps&lt;/strong&gt; even when unsure, rather than returning “I don’t know.”&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Strategies to Prevent or Reduce Hallucinations
&lt;/h2&gt;

&lt;p&gt;Here’s a practical guide to mitigating hallucinations in your AI-powered features.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Ground the Model with RAG (Retrieval-Augmented Generation)
&lt;/h3&gt;

&lt;p&gt;Instead of asking the LLM to generate answers from its pre-trained knowledge, provide it with &lt;strong&gt;contextual documents&lt;/strong&gt; from your own data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You embed your internal documents (PDFs, KBs, FAQs, etc.)&lt;/li&gt;
&lt;li&gt;On user query, retrieve relevant docs → pass them to the LLM&lt;/li&gt;
&lt;li&gt;The model generates responses &lt;em&gt;only&lt;/em&gt; based on what’s retrieved&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tools:&lt;/strong&gt; LangChain, LlamaIndex, Haystack&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Always Cite Sources
&lt;/h3&gt;

&lt;p&gt;Instruct the model to include citations for its answers. This:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Encourages the model to &lt;strong&gt;stay close to the source&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Makes it easier to &lt;strong&gt;verify&lt;/strong&gt; output&lt;/li&gt;
&lt;li&gt;Builds &lt;strong&gt;user trust&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example prompt:&lt;/strong&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Answer using only the provided context. Cite the source file name for each answer.”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  3. Use Function Calling / Tool Use
&lt;/h3&gt;

&lt;p&gt;LLMs are great at orchestrating—but not always accurate. Let them &lt;strong&gt;call APIs, fetch data from a database, or do calculations via plugins&lt;/strong&gt; instead of guessing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
❌ &lt;em&gt;"What's 17% of ₹3,49,000?" → Hallucinated answer&lt;/em&gt;&lt;br&gt;&lt;br&gt;
✅ &lt;em&gt;Let it call a math API&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Implement Output Validation Layers
&lt;/h3&gt;

&lt;p&gt;Don't just trust the output blindly. Run it through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Regex or Schema validation&lt;/strong&gt; (for expected formats)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fact-checking submodels&lt;/strong&gt; or external verification tools&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Human-in-the-loop review&lt;/strong&gt; for high-stakes decisions&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  5. Use Temperature and Top-p Tuning
&lt;/h3&gt;

&lt;p&gt;Lower the &lt;strong&gt;temperature&lt;/strong&gt; to make responses less creative and more deterministic. For factual tasks, this helps reduce the chances of hallucination.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
response = openai.ChatCompletion.create(
  model="gpt-4",
  messages=your_messages,
  temperature=0.2,
)


Bonus: Tell It What NOT to Do

Instructional prompting helps a lot:

“If you are unsure or don’t find the answer in the context, say: ‘I don’t know based on the given data.’”

Models often follow that instruction well. Try combining this with RAG for best results.

Hallucinations won’t go away completely, but you can control and contain them.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>saas</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>What is Rate Limiting and How to Add It in Django</title>
      <dc:creator>Aakash Aggarwal</dc:creator>
      <pubDate>Fri, 11 Apr 2025 12:06:12 +0000</pubDate>
      <link>https://forem.com/aakasha063/what-is-rate-limiting-and-how-to-add-it-in-django-4nkd</link>
      <guid>https://forem.com/aakasha063/what-is-rate-limiting-and-how-to-add-it-in-django-4nkd</guid>
      <description>&lt;p&gt;Have you ever seen an error like “429 Too Many Requests”? That’s because of rate limiting. In this post, we’ll learn:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is rate limiting&lt;/li&gt;
&lt;li&gt;Why it’s important&lt;/li&gt;
&lt;li&gt;How to add rate limiting in a Django project (with simple steps)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What is Rate Limiting?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rate limiting means putting a limit on how many times someone can call your API or access a resource in a specific time.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“You can only make 5 requests per minute.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It helps keep your website or API safe and fair for everyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is Rate Limiting Important?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stop Abuse&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stops bots or attackers from spamming your website.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save Server Resources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoids server overload and crashes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fair Usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Makes sure no one uses more than their share.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better Performance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeps your app fast and smooth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Implement Rate Limiting in Django&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can use a third-party package called &lt;code&gt;django-ratelimit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Install the Package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install django-ratelimit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Add to Your Django View&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.http import JsonResponse
from ratelimit.decorators import ratelimit

@ratelimit(key='ip', rate='5/m', block=True)
def my_api_view(request):
    return JsonResponse({"message": "This is a rate-limited API!"})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;key='ip' → limit by user’s IP address&lt;/li&gt;
&lt;li&gt;rate='5/m' → max 5 requests per minute&lt;/li&gt;
&lt;li&gt;block=True → block extra requests with 429 error&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, Try hitting the API more than 5 times per minute from the same IP. &lt;/p&gt;

&lt;p&gt;You will get&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "detail": "Request was throttled. Expected available in 60 seconds."
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rate limiting is simple but powerful. It keeps your API healthy and safe.&lt;/p&gt;

&lt;p&gt;Let me know if you tried this in your Django project or if you want help with a specific use case!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>django</category>
      <category>python</category>
      <category>security</category>
    </item>
    <item>
      <title>How to Integrate AI into Your Web App in 2025 (Without Losing Your Mind)</title>
      <dc:creator>Aakash Aggarwal</dc:creator>
      <pubDate>Thu, 10 Apr 2025 17:31:53 +0000</pubDate>
      <link>https://forem.com/aakasha063/how-to-integrate-ai-into-your-web-app-in-2025-without-losing-your-mind-48a4</link>
      <guid>https://forem.com/aakasha063/how-to-integrate-ai-into-your-web-app-in-2025-without-losing-your-mind-48a4</guid>
      <description>&lt;p&gt;AI is everywhere in 2025 — chatbots, smart replies, content generators. But did you know it’s actually super easy to add AI to your own web app?&lt;/p&gt;

&lt;p&gt;In this post, I’ll show you how to use OpenAI’s GPT model in a web app to summarize text — like blog posts, notes, or articles. No need to be an AI expert. Just some basic web dev skills and an API key!&lt;/p&gt;

&lt;p&gt;What We’re Building&lt;/p&gt;

&lt;p&gt;A simple app where users can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Paste some text&lt;/li&gt;
&lt;li&gt;Click a button&lt;/li&gt;
&lt;li&gt;Get a smart summary from AI&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What You’ll Need&lt;br&gt;
• Python (we’ll use Flask for the backend)&lt;br&gt;
• OpenAI API key (you can get it from platform.openai.com)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# app.py
from flask import Flask, request, jsonify
import openai
import os

app = Flask(__name__)
openai.api_key = os.getenv("OPENAI_API_KEY")

@app.route('/summarize', methods=['POST'])
def summarize():
    data = request.get_json()
    text = data.get("text", "")

    if not text:
        return jsonify({"error": "No text provided"}), 400

    response = openai.ChatCompletion.create(
        model="gpt-4",
        messages=[
            {"role": "system", "content": "You are a helpful assistant that summarizes text."},
            {"role": "user", "content": text}
        ]
    )
    summary = response['choices'][0]['message']['content']
    return jsonify({"summary": summary})

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to set your OpenAI key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export OPENAI_API_KEY=your_key_here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s It!&lt;/p&gt;

&lt;p&gt;You now have a basic web app that uses AI to summarize text.&lt;/p&gt;

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