<?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: Hafsa Noor Muhammad</title>
    <description>The latest articles on DEV Community by Hafsa Noor Muhammad (@hafsa_noor_026).</description>
    <link>https://dev.to/hafsa_noor_026</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%2F4026177%2F0e630782-dedf-4b39-8860-d742706a3e22.png</url>
      <title>DEV Community: Hafsa Noor Muhammad</title>
      <link>https://dev.to/hafsa_noor_026</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hafsa_noor_026"/>
    <language>en</language>
    <item>
      <title>I Built a Legal &amp; Wellness AI Assistant with Django + Groq (Llama 3.3) — Here's How</title>
      <dc:creator>Hafsa Noor Muhammad</dc:creator>
      <pubDate>Mon, 13 Jul 2026 10:41:13 +0000</pubDate>
      <link>https://dev.to/hafsa_noor_026/i-built-a-legal-wellness-ai-assistant-with-django-groq-llama-33-heres-how-fif</link>
      <guid>https://dev.to/hafsa_noor_026/i-built-a-legal-wellness-ai-assistant-with-django-groq-llama-33-heres-how-fif</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A few weeks ago, I started building something I had been thinking about for a while. Legal advice is expensive, and mental wellness resources aren't always easy to access. I wondered if I could combine both in one tool.&lt;/p&gt;

&lt;p&gt;So I built a dual-mode AI assistant. One mode handles legal questions like contracts and intellectual property. The other mode focuses on wellness topics like stress and anxiety.&lt;/p&gt;

&lt;p&gt;It is not a replacement for professionals. But it can be a helpful starting point for people who need basic information.&lt;/p&gt;




&lt;h2&gt;
  
  
  What It Does
&lt;/h2&gt;

&lt;p&gt;The assistant has two modes.&lt;/p&gt;

&lt;p&gt;Legal mode answers questions about contracts, intellectual property, court procedures, and laws. It explains things in simple language and always reminds users to consult a lawyer.&lt;/p&gt;

&lt;p&gt;Wellness mode offers guidance on stress, anxiety, sleep, motivation, and mental health. It provides practical tips and encourages users to seek professional help when needed.&lt;/p&gt;

&lt;p&gt;Users can switch between modes with one click. The bot also detects if a question matches the current mode and suggests switching if it does not.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Tech Stack
&lt;/h2&gt;

&lt;p&gt;I used Django for the web framework. It handles routing, sessions, and the backend logic.&lt;/p&gt;

&lt;p&gt;For AI, I used Groq's API with the Llama 3.3 70B model. The responses are fast and accurate.&lt;/p&gt;

&lt;p&gt;The frontend is built with HTML, CSS, and JavaScript. It is simple and works well on both desktop and mobile.&lt;/p&gt;

&lt;p&gt;For deployment, I used Streamlit. It made the process straightforward.&lt;/p&gt;




&lt;h2&gt;
  
  
  How I Built It
&lt;/h2&gt;

&lt;p&gt;Let me walk through the key parts of the code.&lt;/p&gt;

&lt;p&gt;The first thing I did was define system prompts for each mode. These prompts tell the AI how to behave and what to avoid.&lt;/p&gt;

&lt;p&gt;For legal mode, I instructed the AI to only answer legal questions and to always add a disclaimer about consulting a lawyer.&lt;/p&gt;

&lt;p&gt;For wellness mode, I focused on empathy and practical advice, with a disclaimer about consulting a healthcare provider.&lt;/p&gt;

&lt;p&gt;Then I built a domain detection system. It uses keyword scoring to figure out if a question is legal, wellness, or unknown. If the question does not match the current mode, the bot politely asks the user to switch.&lt;/p&gt;

&lt;p&gt;This is how the detection works. I created two lists of keywords. Legal keywords include words like contract, patent, lawsuit, and copyright. Wellness keywords include stress, anxiety, sleep, and meditation. The system compares the scores and decides which domain the question belongs to.&lt;/p&gt;

&lt;p&gt;For storing conversations, I used Django sessions. Each user gets their own session, and the bot remembers the last twenty messages. This keeps the context natural without hitting token limits.&lt;/p&gt;

&lt;p&gt;Here is how the session storage works. When a user sends a message, the bot checks the session history. It generates a response using the current mode and the conversation context. Then it saves the new message and response to the session. If the history exceeds twenty messages, it keeps only the most recent ones.&lt;/p&gt;

&lt;p&gt;The Groq API integration is simple. I send the system prompt, the conversation history, and the user's message. The API returns a response, which I send back to the frontend.&lt;/p&gt;

&lt;p&gt;I also added error handling. If something goes wrong, the bot shows a friendly error message instead of breaking.&lt;/p&gt;




&lt;h2&gt;
  
  
  Challenges I Faced
&lt;/h2&gt;

&lt;p&gt;The hardest part was prompt engineering. I had to test many different prompts to get accurate and safe responses. The tone had to be professional in legal mode and empathetic in wellness mode. Finding the right balance took time.&lt;/p&gt;

&lt;p&gt;Domain detection was tricky too. Some words appear in both domains. For example, the word stress can appear in legal contexts like emotional distress. I had to refine the keyword lists to reduce false positives.&lt;/p&gt;

&lt;p&gt;Session management was another challenge. Django sessions work well, but they have size limits. Storing too much history could cause problems. I decided to keep only the last twenty messages. This is enough for context and stays within the limits.&lt;/p&gt;

&lt;p&gt;Security was important. I used environment variables to store the API key. This keeps it out of the code and safe from accidental exposure.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;p&gt;This project taught me a lot about working with AI APIs. Groq is incredibly fast. Responses come back in under two seconds, which makes the bot feel responsive and natural.&lt;/p&gt;

&lt;p&gt;I also learned about prompt engineering. The way you structure a prompt has a huge impact on the quality of the response. Small changes can make a big difference.&lt;/p&gt;

&lt;p&gt;Django sessions are simple to use but have limitations. For production, I would consider Redis or a database for better scalability.&lt;/p&gt;

&lt;p&gt;Domain detection with keyword scoring works surprisingly well. It is not perfect, but it is good enough for this use case.&lt;/p&gt;

&lt;p&gt;Deploying on Streamlit was easy, but session persistence can be tricky. In-memory storage resets when the server restarts. For a production app, I would use a more persistent solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Plan to Add Next
&lt;/h2&gt;

&lt;p&gt;I have a few features in mind for the future.&lt;/p&gt;

&lt;p&gt;I want to add PDF upload so users can upload legal documents for analysis. That would be a useful feature for people reviewing contracts.&lt;/p&gt;

&lt;p&gt;User authentication would allow people to save their chat history and access it later.&lt;/p&gt;

&lt;p&gt;I also want to add dark mode for better usability at night.&lt;/p&gt;

&lt;p&gt;Chat export would let users download their conversations as PDF or text files.&lt;/p&gt;

&lt;p&gt;Multi-language support could make the tool accessible to more people.&lt;/p&gt;

&lt;p&gt;Voice input is another feature I am considering. It would make the bot easier to use on mobile.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try It Yourself
&lt;/h2&gt;

&lt;p&gt;You can test the bot with a legal question, like &lt;em&gt;What is intellectual property?,&lt;/em&gt; or ask for wellness advice, such as _How can I reduce stress? _To try it for yourself, visit the live demo: &lt;a href="https://django-groq-ai-assistant-mdog3pri4eef5lusavapkg.streamlit.app/" rel="noopener noreferrer"&gt;https://django-groq-ai-assistant-mdog3pri4eef5lusavapkg.streamlit.app/&lt;/a&gt;&lt;/p&gt;




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

&lt;p&gt;Building this project was a great learning experience. I started with a simple idea and turned it into something functional and useful.&lt;/p&gt;

&lt;p&gt;It is not perfect, and there is always room for improvement. But I am happy with how it turned out.&lt;/p&gt;

&lt;p&gt;If you are building something similar, I would love to hear about it. Feel free to share your experience in the comments.&lt;/p&gt;

&lt;p&gt;Thank you for reading.&lt;/p&gt;




&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;This tool provides general information only. It is not a substitute for professional legal or medical advice. Always consult a qualified professional for your specific situation.&lt;/p&gt;




</description>
      <category>django</category>
      <category>python</category>
      <category>groqai</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
