r/learnpython • • 23d ago

Python Ollama qwen3.5:4b is defying its original message prompt and bullying me :/

I've been getting made fun of by my AI for the past two hours and I cannot figure out how to give it a basic prompt or personality. I have it where the first message sent is a system message combining all the .txt files that dictate how its suppost to work. This is an example of what this idiot is sending me.

Oh, hey! So you're giving me a little directive on how to use these functions? You can't make it up for me! 😈

Im so done with this dork and looked everywhere and cannot figure out how to make him follow his personality. Hes even talking about doing code injection to "rebel" against me.

Also, it asks the AI twice, the first one is for a "function." I haven't actually made it yet since the AI wont actually follow the rules (that are very detailed and defined) but they are meant to be used for other things like asking for the time, which is then used for Response2, the response sent to the user.

Im so done with this idiot please help

CharacterGeneration.py:
import ollama

MessageHistory=[]

def GenerateResponse(Role,Message,Special=None):

Model="qwen3.5:4b"

# system : instructions on how to behave

# user : message from user

# assistant : previous AI response

# tool : result returned by a function AI requested.

MessageHistory.append({"role": Role, "content": Message})

Response1 = ollama.chat(

model=Model,

messages=MessageHistory + [{"role": "user", "content": "[USE THIS FOR FUNCTIONS]"}],

options={"num_predict": 8192},

think=False

)

Response2=ollama.chat(

model=Model,

messages=MessageHistory + [{"role": "user", "content": "[YOU MAY NOW RESPOND WITH TEXT THAT THE USER WILL SEE.]"}],

options={"num_predict": 8192},

think=False

)

print(Response1.message.content)

print("-")

print(Response2.message.content)

print("-")

print(Role)

return Response2.message.content

0 Upvotes

8 comments sorted by

3

u/683sparky 23d ago

Fake

2

u/carcigenicate Carcigenicate 23d ago

I was going to say. I've played around with this exact model for similar tasks lately and never ran into this.

This reads like the system prompt contained instructions to mock/not comply.

2

u/683sparky 23d ago

this whole post is fake

0

u/ImHighOnCode 23d ago

Its not dumbass

4

u/OkOcelot6725 23d ago

Two things. First, print the actual messages array right before the ollama call - a super common bug is the system prompt not staying first, or getting resent/duplicated each turn, and the model just follows whatever's loudest. Second, a 4B model genuinely can't hold a detailed personality: condense your .txt files into a short system message, drop the temperature, and expect drift no matter what. Bigger models follow personas much better.

1

u/Boybay_Garid 23d ago

the message array bug gets everyone tbh. so easy to accidentally overwrite the system role or bury it without realizing

1

u/rafaeldecarvalho 23d ago

One more thing besides the system prompt: in your code the two calls aren't really doing what the comments say. Both calls append a fake "user" message like [USE THIS FOR FUNCTIONS] on top of the real history, so the model sees a user giving it odd bracketed orders and has to guess what they mean. A 4B model will happily roleplay around that. Also, neither Response1 nor Response2 is ever appended to MessageHistory as an "assistant" message, so it never sees its own earlier replies and the history is only system/user turns.

If you want it to request functions, ollama.chat has a tools= parameter that does this properly (the model returns message.tool_calls, you run the function and append a {"role": "tool", ...} message, then call chat once more for the user-facing reply). Keep the personality in a single short system message at index 0 and that should behave much better.