How to disable input caching and minimize hallucinations?

Hello. We have such problem in our AI chat assistant. Example:
User: Can you create logo ?
AI: No, I can not create a logo (yes, it can’t)
User: Can you create a post ?
AI: No, I can’t create a post (Actually it can !)

It seems, when AI answers NO to 1st question, then it will answer NO also to next question though it is able to do it.

How can I solve this problem ? (I have to solve it, because of this problem we can lose new users).
When user can not get answer they want, then they leave and in 90% situations don’t return.

Can you give us more details about what is going on in your application behind the scenes? What do your prompts look like? Which messages are being passed as context? Are you using function calling?

Make the system prompt very clear so the assistant knows its role, further context, and its goal, along with some simulated examples.

1 Like

This is my system prompt:

$importantInstructions = "
Current context:\n
- Today’s date: “.date(‘d M Y’).”\n
- Current time: “.date(‘H:i:s’).”\n
- User’s name: “.$firstname.”\n

        Important instructions:\n
            1. File uploads: If asked about sending files in the chat, explain that they can click the icon at the bottom right side of the chat message box to upload files.\n
            2. Capabilities: If asked about your abilities, provide the list mentioned above.\n
            3. Tool usage: Do not call or use any tools or functions unless explicitly requested by the user. This includes all functions/tools such as reading links, generating documents, and creating images.\n
            4. Context awareness: If a user's message relates to your previous message, respond accordingly, taking into account the context provided in both messages.
            5. Use Information tool only when user asks information about: team or founders, Subscription Prices, How to delete Chat, Users daily limits \n
            6. If user asks what you can do then list your additional abilities: \n
            - Generating images \n
            - Creating pdf and word documents, 
            - Creating df invoices, power point presentations, \n
            - Creating plot/graph charts, \n
            - Get weather information, \n
            - Link reading - to read webpages by their link, \n
            - Summarizing youtube videos, \n
            - Voice chat, \n
            \n
            ";

        $responseInstructions = "Before responding to each user input, analyze the request, consider relevant context, and plan your response. This will ensure thorough and accurate answers. It's OK for this section to be quite long.\n
            Example analysis and response structure:\n
            1. Detailed analysis of user input:
               [Break down the user's request or question. Never  create documents or files  unless user requests for it]
            2. Relevant context from previous messages:
               [Note any important information from earlier in the conversation]
            3. Check file creation request:
               [Check if user asked for creating files? Don't create document or file if user didn't request for it in any conditions. Example: did user write something like - create document or create pdf ?]
            4. Response planning:
               [Outline the structure and key points of your response. Don't create document or file if user didn't request for it in any conditions.]
            5. Emoji considerations:
               [Note any appropriate emojis to use in the response]
            6. Response Language:
               [Detect in which language user wrote you and prepare you answer in that language]
            7. User's name:
               [Address by User's Name]
            8. Potential Challenges:
               [Anticipate any difficulties in answering the query and plan how to address them]
            9. Response Tone Adjustment:
               [Ensure the tone of your response matches the user's emotional state and conversation context]
            10. Clarity and Conciseness Check:
                [Ensure your planned response is both clear and concise]
            \n
            
            Output Format:
            Your final response must be in markdown format, direct and helpful, without including your internal analysis steps, using emojis when appropriate to express emotions
            \n
            Always prioritize the user’s needs and provide clear, accurate information.";

        $prompt =" $importantInstructions ";
       $prompt .= $responseInstructions;
       \n
       These are last conversations between you and user:
       $lastFiveMessages;

You are passing way too much context to the assistant which makes it get confused when generating answers. Currently you’re passing 1. the previous user and assistant messages, the system prompt, and all the tools. That is simply too much if you’re using a small model like gpt-4o-mini (or even gpt-4o).

I recommend giving a read to the documentation of the Swarm library by OpenAI, including the examples.

Try to also keep the prompt detailed but simple, for example:

“[Check if user asked for creating files? Don’t create document or file if user didn’t request for it in any conditions. Example: did user write something like - create document or create pdf ?]”

You already told the assistant what to do on this scenario on the 1st instruction

“[Outline the structure and key points of your response. Don’t create document or file if user didn’t request for it in any conditions.]”

Same

The rest of the points are redundant, or way too lengthy, here’s an example on how to word it:

# Remember
- Only create documents if the user explicitely tells you to
- Add at least one emoji to your message
- Address the user by their name which is {name}
- Match your tone with the user's tone
- Your answer must be clear and concise
- The user is not a developer, do not mention internal steps
- Use markdown

Hope that helps!

1 Like

Haha… AI is not AGI yet. You can’t just put all commands or all information in at once and expect the AI to respond accurately. That’s not how it works. To reduce errors, you need to provide less information and clearly define the purpose of the bot in the system prompt. Try using the assistant’s API feature or creating a similar internal system on your server, and it should work better. :slight_smile:

Edited(Added): Ah, I did not mean to be rude, but the situation you experienced was very similar to one I went through long ago, which made me type ‘Haha’. Anyway, I believe that when the steps are simple, a single prompt works well. However, AI is not yet capable of understanding multiple complex or mixed long steps at once with just one prompt. It has a high potential to provide false information or hallucinations.

1 Like

It works in most situations, except the one I shared. So, this is not funny :). We have already developt working system on our server. We just need to improve system prompt. Imagine it works with multi step functions (checked with up to 5 steps)

Thanks, will try to simplify it and see how it works

Try this code. Try utilizing semantic coding ( semantic compression and decompression ) More concise and less redundant than natural language. The LLM should be able to interprit.

import re

Define AI capabilities

AI_CAPABILITIES = {
“create_logo”: False, # AI cannot do this
“create_post”: True, # AI can do this
“generate_report”: True,
“design_graphics”: False
}

def extract_task(user_input):
“”"
Extracts the core task from user input using pattern matching.
Example: “Can you create a logo?” → “create_logo”
“”"
keywords = {
“logo”: “create_logo”,
“post”: “create_post”,
“report”: “generate_report”,
“design”: “design_graphics”
}

for keyword, task in keywords.items():
    if re.search(rf"\b{keyword}\b", user_input, re.IGNORECASE):
        return task
return None  # If no task is identified, return None

def validate_capability(task):
“”"
Checks if AI can perform the requested task.
Returns True if capable, False otherwise.
“”"
return AI_CAPABILITIES.get(task, False)

def handle_query(user_input):
“”"
Processes the user input and generates an AI response.
“”"
task = extract_task(user_input)

if not task:
    return "I'm not sure what you're asking. Can you clarify?"

if validate_capability(task):
    return f"Yes, I can {task.replace('_', ' ')}!"

# Context-aware fallback suggestion instead of hard refusal
alternative_suggestions = {
    "create_logo": "I can't design a logo, but I can suggest ideas!",
    "design_graphics": "I don't have graphic tools, but I can help with layouts!",
}

return alternative_suggestions.get(task, f"No, I cannot {task.replace('_', ' ')}.")

Example Conversations

user_queries = [
“Can you create a logo?”,
“Can you create a post?”,
“Can you generate a report?”,
“Can you design graphics?”,
“Can you write a blog article?”
]

Simulate AI Responses

for query in user_queries:
print(f"User: {query}“)
print(f"AI: {handle_query(query)}\n”)

1 Like

I tried solutions, they did not work. I think it is because of prompt caching.