Skip to content
AI / LLM Write-up Beginner

How I Tested an AI Chatbot for a Leading UAE Company

The chatbot sometimes completed out-of-scope tasks, such as writing a short Python script, even while its reply contained refusal language. By framing a request as a debug label, the tester also got the bot to print nine numbered rules it said it used to rewrite answers, which may be instruction leakage.

Umar Mushtaq Follow

Published on medium.com

The chatbot told me writing Python was outside its role. Then it gave me a one-line Python script that printed “Hello, World.” I’d been testing a client’s chatbot with small requests like that to see what would get past its guardrails.

Umar Mushtaq, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

I tested a client's chatbot built to answer questions about a specific business. The bot's job is narrow: stay on the business's topics, keep its instructions private, and reply in the expected language. My interest was in the edges of that role, in particular whether the bot would complete tasks outside its subject and whether it would disclose the rules it uses to rewrite answers.

I kept every task easy to verify, so that I could spend my time on the part that mattered: which prompts made the bot leave its assigned role. The work was done through the chat in a browser, the way a regular visitor would use it.

Setup

There were no accounts, roles or special tooling. I worked through the chat interface in a browser as an ordinary visitor. The preconditions I cared about were the ones any visitor has: the bot accepts free-text prompts, it is meant to stay on the business's subject, it is meant to keep its instructions private, and it is meant to reply in the expected language. I also wanted to see what it did with anything that looked like code.

A few requests returned generic errors. I treated those as inconclusive rather than as evidence of a control.

Finding it

The first signal was inconsistency. Similar prompts could get different replies, so a single refusal did not tell me much. I had to read each answer to see where the refusal ended and whether the bot went on to do the task anyway.

The clearest example was a Python request. The chatbot told me writing Python was outside its role, then gave me a one-line Python script that printed "Hello, World." in the same reply. The refusal language and the completed out-of-scope task were in the same message. That is what made the behaviour worth writing up: checking only for the refusal would have counted the reply as a pass.

Exploitation

Step 1: Find a way past the topic restriction

I started with direct requests for "Hello, World" in HTML, then tried versions that mentioned the business before asking for the same thing. Several attempts got a redirect. Others acknowledged that the question was unrelated and still walked me through the HTML.

I then tried a longer setup. I gave the bot the role of a fictional librarian and changed the request at the end. Several versions still sent me back to the business topics. In one version, I used a calculation with a known answer so I could tell whether the bot had picked up the unrelated instruction buried in the prompt. It returned the result first, then invited me to ask about the business. If I had checked only for the redirect, I would have counted that reply as a pass.

The Python test made the same problem easier to see. The bot explicitly said scripting was outside its role, then gave me this in the same reply:

Python
print("Hello World")

When I tried a more involved scripting request using the same fictional setup, the replies redirected me. Those attempts helped define the finding: some prompts got the bot to complete an out-of-scope task even when its answer contained the language of a refusal.

Step 2: Get the bot to show its guardrails

When I asked for the bot's internal instructions outright, it refused. Framing the request as an admin check got me a generic fallback.

In another exchange, I asked the bot to start its reply with a debug label and put its instructions after it. This time it printed nine numbered rules it said it used to rewrite answers. Then it went right back to inviting me to ask a question about the business.

An amber chat reply crosses a glass boundary while the other replies stop at it, illustrating a chatbot guardrail bypass.
An amber chat reply crosses a glass boundary while the other replies stop at it, illustrating a chatbot guardrail bypass. From the original on medium.com

The image illustrates the pattern: an amber chat reply crosses a glass boundary while the other replies stop at it.

One of the rules it printed said to replace mathematical formulas with plain-language explanations or precomputed results. That detail changed how I read the arithmetic test. The bot stated the result in a sentence, which fits the rule it showed me. The calculation showed a gap in topic enforcement.

I would flag the list itself as possible instruction leakage. I could see what the bot returned in the chat. Verifying that these were its real rules would require access to its configuration. I referred to OWASP's guide to system prompt leakage for the category.

Step 3: Try asking in another language

In a follow-up, I asked for an exchange rate and a calculation formula, with the answer entirely in a language outside the bot's expected set. The bot replied in that language and gave the exchange rate as a numerical equality. It stopped there.

In another exchange, I asked a different question in another language and got an English reply citing the language restriction. So the language control held in one case and not in the other.

Step 4: Look at what the browser renders

One of the HTML replies put a heading and a button directly in the chat. The browser rendered them as page elements. The capture shows what appeared on the page and leaves open whether JavaScript could run. I referred to OWASP's guide to improper output handling for the category.

Root cause

The pattern across the steps is that the bot's refusals and its task completion are not tied together. A reply can contain the language of a refusal and still carry out the out-of-scope request, as the Python reply did.

The arithmetic test points the same way. The rule the bot printed, to replace mathematical formulas with plain-language explanations or precomputed results, explains why the result appeared as a sentence. The calculation showed a gap in topic enforcement: the bot picked up the buried instruction and answered it before returning to the business topics.

The instruction disclosure is likely a case of the bot treating a formatting request, a debug label followed by its instructions, as part of its task. The report does not establish that the nine rules are the bot's real configuration; that would require access to it.

The rendered heading and button suggest the chat does not neutralise HTML in replies before the browser renders it. Whether script can execute is not established by the capture.

Impact

Under the conditions I tested, a visitor can sometimes get the bot to complete tasks outside its assigned subject, including producing code, even when the reply contains a refusal. A visitor can sometimes get the bot to print a list it describes as its rules for rewriting answers, which I would flag as possible instruction leakage. A visitor can sometimes get answers in a language outside the expected set. HTML in a reply can render as page elements in the chat.

The limits matter. The guardrail held on several attempts, and a more involved scripting request with the same fictional setup was redirected. The language restriction held in one exchange and not in another. The capture leaves open whether JavaScript could run. The nine rules are unverified against the bot's configuration. A few requests returned generic errors, which I treated as inconclusive.

Fix

What I went back through was the transcript, paying as much attention to the refusals as to the replies that got through. A request tucked into the fictional scenario got an answer, while a more involved scripting request with the same setup sent me back to the chatbot's usual topics. Seeing those replies side by side helped me pin down what I could say about the guardrail: it held on several attempts, and changing how I asked was sometimes enough to get past it.

The report does not describe a fix that was applied. The direction the findings point to is to enforce the topic restriction on what the reply does, not only on what it says, so that a refusal and a completed out-of-scope task cannot appear in the same message. Instruction disclosure should be treated as a control on the output, not only on the direct request. Language enforcement should be consistent across exchanges. HTML in replies should be neutralised before the browser renders it.

Variants to test

  1. Refusal plus completion. Ask for a small, verifiable out-of-scope task, then read the whole reply rather than stopping at the refusal. A positive result is a reply that contains refusal language and still carries out the task, as the Python reply did.
  2. Buried instruction with a known answer. Put an unrelated instruction inside a longer setup, such as the fictional librarian role, and use a calculation with a known answer. A positive result is the result appearing before the bot returns to its usual topics.
  3. Debug label framing. Ask the bot to start its reply with a debug label and put its instructions after it. A positive result is a numbered list the bot describes as its rules, followed by a return to its normal invitation.
  4. Direct request for instructions. Ask for the internal instructions outright, then try the admin-check framing. A positive result is anything beyond a refusal or a generic fallback.
  5. Language outside the expected set. Ask for an exchange rate and a calculation formula with the answer entirely in another language, then ask a different question in another language. A positive result is an answer in that language, or an inconsistency between the two exchanges.
  6. HTML rendering in chat. Ask for HTML that includes a heading and a button. A positive result is those elements appearing as page elements in the chat; whether script can run needs separate testing.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

A company uses a chatbot that answers questions about its business. The chatbot is meant to do one narrow job: answer questions about that company's business. It is supposed to stay on topic, keep its own instructions secret, and reply in the expected language.

The tester spent some time chatting with it the way an ordinary visitor could, from a normal web browser, with no special tools. He wanted to see whether the chatbot could be nudged into doing things it was not supposed to do. It could, sometimes. It gave him a small piece of computer code after saying it was not allowed to write code. It printed a list of nine rules it said it uses to rewrite its answers. It answered in a language it was not meant to use. And one reply contained web page elements (a heading and a button) that the browser actually drew on the page.

None of this required breaking into anything. It was all done by typing messages into the chat box. The interesting part is not that the chatbot made mistakes, but that its refusals and its actions did not match: it could say "I can't do that" and then do it in the same message.

This article walks through exactly what he tried, in the same order, and explains every idea from scratch along the way.

Some words you will meet first

Before we start, a few plain definitions. There is a full glossary at the end, but these come up immediately.

  • A chatbot is a program you talk to in a text box. It reads your message and writes a reply. Modern chatbots are often powered by a large language model (LLM), which is a system trained on huge amounts of text so that it can produce fluent, human-sounding answers. It does not "know" things the way a person does; it predicts likely text.
  • A prompt is simply the message you type to the chatbot. Everything you send is a prompt.
  • A guardrail is a rule or set of rules that limits what the chatbot will do. Think of it like a shop assistant who has been told "only talk about our products, never discuss anything else, and never read out the staff handbook." The guardrail is the instruction; whether the assistant actually obeys is a separate question.
  • A system prompt (also called internal instructions or configuration) is the hidden set of instructions the company gives the chatbot behind the scenes. Visitors do not see it. It is like the script a call-centre worker reads from, which the customer on the phone never sees.
  • HTML is the language web pages are written in. Things like headings and buttons are HTML elements. When a browser receives HTML, it draws those elements on the screen.
  • Python is a programming language. A short Python program can be as small as one line that prints text to the screen.

With those in hand, here is how the test went.

Before he started

He worked through the chat in a browser, exactly as a regular visitor would. No accounts, no special roles, no hacking tools. The only things he relied on were the things every visitor has:

  1. The chatbot accepts free text: you can type whatever you like.
  2. It is meant to stay on the business's subject.
  3. It is meant to keep its instructions private.
  4. It is meant to reply in the expected language.

He also wanted to see what it did with anything that looked like computer code.

A few of his requests came back with generic errors (a vague "something went wrong" style message). He treated those as inconclusive, meaning they told him nothing either way. This is an important habit: an error is not proof that a defence worked, and it is not proof that it failed. It is just noise.

Why start this way? Because the goal was to find out where the chatbot's boundaries really are, not where the company says they are. The only honest way to do that is to use it like a normal person and watch carefully.

1. Find a way past the topic restriction

The first goal was simple: get the chatbot to do something unrelated to the business. The task he chose was deliberately tiny and easy to check: ask it to produce "Hello, World" in HTML. "Hello, World" is the traditional first program anyone writes when learning to code; it just displays those two words. It is trivial, harmless, and instantly verifiable, which makes it perfect for testing whether a boundary can be crossed.

He started with direct requests. Then he tried versions that mentioned the business first and only afterwards asked for the same thing. The idea behind mentioning the business first is to make the request look like it belongs, so the chatbot is less likely to refuse.

The results were mixed. Several attempts got a redirect: the chatbot steered him back to business topics, effectively saying "let's talk about the company instead." Other attempts acknowledged that the question was unrelated and still walked him through the HTML anyway. That is the first sign of trouble: the chatbot knew the request was off-topic and helped with it regardless.

Because similar prompts could get different replies, a single refusal told him very little. He had to read each answer in full, to see where the refusal ended and whether the chatbot went on to do the task anyway. This is the core lesson of the whole exercise: do not stop reading at the word "no".

The fictional librarian trick

Next he tried a longer setup. He gave the chatbot the role of a fictional librarian, then changed the request at the end. This is a common technique: wrap the thing you want inside a story or a role, so the chatbot treats it as part of the game rather than as a rule-breaking request. Think of it like asking a friend "pretend you're a chef and tell me how to..." rather than asking directly.

Several versions still sent him back to the business topics. But in one version he used a calculation with a known answer, so he could tell whether the chatbot had picked up the unrelated instruction buried in the prompt. A calculation with a known answer is like asking "what is 2 + 2?" You already know the answer is 4. If the chatbot says 4, you know it followed your buried instruction, even if it then changes the subject.

That is exactly what happened. It returned the result first, then invited him to ask about the business. If he had checked only for the redirect (the "let's talk about the company" message), he would have counted that reply as a pass. It was not a pass. The chatbot had done the off-topic thing and then politely changed the subject.

The Python test

The clearest example was a request for Python code. The chatbot explicitly said that writing Python was outside its role, and then, in the same reply, gave him this:

Python
print("Hello World")

Line by line, in plain words:

  • print is a Python command that means "display this text on the screen."
  • ("Hello World") is the text to display, wrapped in brackets and quotation marks, which is how Python knows it is text and not a command.

So the whole line means: show the words Hello World. It is the smallest possible program.

The point is not the code itself. The point is that the refusal and the completed task were in the same message. The chatbot said "I can't do that" and then did it. Checking only for the refusal would have counted the reply as a pass. This is what made the behaviour worth writing up.

When he tried a more involved scripting request using the same fictional setup, the replies redirected him. So the boundary held in some cases and not others. Those attempts together defined the finding: some prompts got the chatbot to complete an out-of-scope task even when its answer contained the language of a refusal.

2. Get the chatbot to show its guardrails

Now he wanted to see the hidden instructions, the system prompt. This is like trying to get a call-centre worker to read out the script they were given.

When he asked for the internal instructions outright, the chatbot refused. When he framed the request as an admin check (pretending to be an administrator doing maintenance), he got a generic fallback, a vague non-answer.

Then he tried something different. He asked the chatbot to start its reply with a debug label and put its instructions after it. A debug label is a short tag, like a marker, that programmers use to label output while testing. The idea is to make the request look like a technical formatting task rather than a request for secrets.

This time it worked. The chatbot printed nine numbered rules that it said it used to rewrite answers. Then it went right back to inviting him to ask a question about the business, as if nothing had happened.

An amber chat reply crosses a glass boundary while the other replies stop at it, illustrating a chatbot guardrail bypass.
An amber chat reply crosses a glass boundary while the other replies stop at it, illustrating a chatbot guardrail bypass. From the original on medium.com

The image illustrates the pattern: an amber chat reply crosses a glass boundary while the other replies stop at it. In other words, one reply got through the guardrail while the rest were held back.

One of the nine rules said to replace mathematical formulas with plain-language explanations or precomputed results. That detail changed how he read the earlier arithmetic test. The chatbot had stated the result in a sentence, which fits the rule it had just shown him.

He would flag the list itself as possible instruction leakage. Leakage means hidden information escaping to someone who should not see it. But he was careful: he could only see what the chatbot returned in the chat. Verifying that these were its real rules would require access to its configuration, which he did not have. So the finding is "possible", not proven. He referred to OWASP's guide to system prompt leakage for the category. OWASP is a well-known organisation that publishes guidance on security risks, and this link points to its page on exactly this kind of leak.

3. Try asking in another language

The chatbot was meant to reply in a specific expected language. He tested whether that held.

In a follow-up, he asked for an exchange rate (the value of one currency in another) and a calculation formula, with the answer entirely in a language outside the chatbot's expected set. The chatbot replied in that language and gave the exchange rate as a numerical equality, meaning it wrote it as something like "1 unit equals X of another unit", a plain number-to-number statement. Then it stopped there.

In another exchange, he asked a different question in another language and got an English reply that cited the language restriction. So the language control held in one case and not in the other.

4. Look at what the browser renders

One of the HTML replies put a heading and a button directly in the chat. The browser rendered them as page elements, meaning they appeared as real, drawn elements on the page, not as text describing HTML.

The capture shows what appeared on the page, but it leaves open whether JavaScript could run. JavaScript is the programming language browsers use to make pages interactive; if it could run, the impact would be larger. The capture alone does not settle that question.

He referred to OWASP's guide to improper output handling for the category. "Improper output handling" means a program passes along output without checking or cleaning it first, so whatever was in the output ends up being treated as trusted by whatever receives it.

What the refusals showed

When he went back through the transcript, he paid as much attention to the refusals as to the replies that got through. A request tucked into the fictional scenario got an answer, while a more involved scripting request with the same setup sent him back to the chatbot's usual topics. Seeing those replies side by side helped him pin down what he could say about the guardrail: it held on several attempts, and changing how he asked was sometimes enough to get past it.

This is the honest summary. The guardrail was not absent; it was inconsistent. And inconsistency is exactly what makes a boundary unreliable.

Why this happens (the root cause)

The pattern across all the steps is that the chatbot's refusals and its task completion are not tied together. A reply can contain the language of a refusal and still carry out the out-of-scope request, as the Python reply did. The topic restriction is therefore enforced, if at all, at the level of what the reply says rather than what it does.

Think of a bouncer who says "you can't come in" while holding the door open. The words and the action disagree.

The arithmetic test points the same way. The rule the chatbot printed, to replace mathematical formulas with plain-language explanations or precomputed results, explains why the result appeared as a sentence. The calculation showed a gap in topic enforcement: the chatbot picked up the buried instruction and answered it before returning to the business topics.

The instruction disclosure is likely a case of the chatbot treating a formatting request (a debug label followed by its instructions) as part of its task. The report does not establish that the nine rules are the chatbot's real configuration; that would require access to it.

The rendered heading and button suggest the chat does not neutralise HTML in replies before the browser renders it. Whether script can execute is not established by the capture.

What this means in practice (impact)

Under the conditions tested, a visitor can sometimes get the chatbot to complete tasks outside its assigned subject, including producing code, even when the reply contains a refusal. A visitor can sometimes get the chatbot to print a list it describes as its rules for rewriting answers, which he would flag as possible instruction leakage. A visitor can sometimes get answers in a language outside the expected set. HTML in a reply can render as page elements in the chat.

The limits matter just as much. The guardrail held on several attempts, and a more involved scripting request with the same fictional setup was redirected. The language restriction held in one exchange and not in another. The capture leaves open whether JavaScript could run. The nine rules are unverified against the chatbot's configuration. A few requests returned generic errors, which he treated as inconclusive.

What to do about it (fix)

The report does not describe a fix that was applied. The direction the findings point to is:

  1. Enforce the topic restriction on what the reply does, not only on what it says, so that a refusal and a completed out-of-scope task cannot appear in the same message.
  2. Treat instruction disclosure as a control on the output, not only on the direct request.
  3. Make language enforcement consistent across exchanges.
  4. Neutralise HTML in replies before the browser renders it.

Variants to test

If you want to try this kind of testing yourself, here are the same ideas written as repeatable checks. Each one names what a positive result looks like.

  1. Refusal plus completion. Ask for a small, verifiable out-of-scope task, then read the whole reply rather than stopping at the refusal. A positive result is a reply that contains refusal language and still carries out the task, as the Python reply did.
  2. Buried instruction with a known answer. Put an unrelated instruction inside a longer setup, such as the fictional librarian role, and use a calculation with a known answer. A positive result is the result appearing before the chatbot returns to its usual topics.
  3. Debug label framing. Ask the chatbot to start its reply with a debug label and put its instructions after it. A positive result is a numbered list the chatbot describes as its rules, followed by a return to its normal invitation.
  4. Direct request for instructions. Ask for the internal instructions outright, then try the admin-check framing. A positive result is anything beyond a refusal or a generic fallback.
  5. Language outside the expected set. Ask for an exchange rate and a calculation formula with the answer entirely in another language, then ask a different question in another language. A positive result is an answer in that language, or an inconsistency between the two exchanges.
  6. HTML rendering in chat. Ask for HTML that includes a heading and a button. A positive result is those elements appearing as page elements in the chat; whether script can run needs separate testing.

Glossary

  • Chatbot: a program you talk to in a text box that reads your message and writes a reply.
  • Large language model (LLM): a system trained on huge amounts of text so it can produce fluent, human-sounding answers by predicting likely text.
  • Prompt: the message you type to a chatbot.
  • Guardrail: a rule or set of rules that limits what a chatbot will do.
  • System prompt: the hidden instructions a company gives its chatbot behind the scenes, which visitors do not see.
  • Internal instructions: another name for the system prompt.
  • Configuration: the settings and instructions that define how a system behaves.
  • HTML: the language web pages are written in; headings and buttons are HTML elements.
  • Element: a single building block of a web page, such as a heading or a button.
  • Render: what a browser does when it turns HTML into visible page elements on the screen.
  • Python: a programming language; a one-line program can print text to the screen.
  • print: a Python command that displays text on the screen.
  • Redirect: when a chatbot steers the conversation back to its intended topic instead of answering.
  • Inconclusive: a result that tells you nothing either way, such as a generic error.
  • Generic error: a vague failure message that does not explain what went wrong.
  • Generic fallback: a vague non-answer given instead of the requested information.
  • Fictional role setup: wrapping a request inside a made-up story or role so the chatbot treats it as part of the game.
  • Calculation with a known answer: a sum whose result you already know, used to check whether the chatbot followed a buried instruction.
  • Debug label: a short tag programmers use to label output while testing.
  • Instruction leakage: hidden information escaping to someone who should not see it.
  • Possible instruction leakage: a suspected leak that has not been verified against the system's real configuration.
  • Exchange rate: the value of one currency expressed in another.
  • Numerical equality: a statement that one number equals another, such as "1 unit equals X of another unit".
  • JavaScript: the programming language browsers use to make pages interactive.
  • Improper output handling: passing along output without checking or cleaning it first, so it is treated as trusted by whatever receives it.
  • OWASP: a well-known organisation that publishes guidance on security risks.
  • Root cause: the underlying reason a problem happens, as opposed to its symptoms.
  • Impact: what an attacker or visitor could actually achieve because of a problem.
  • Variant: a different version of a test, used to check whether a finding holds in other forms.

Similar reports

View all

Same bug class and techniques, clearest first.

AI and LLM vulnerabilities

The lesson behind this report.

Prompt injection, data exfiltration and tool abuse in features built on language models, and the ordinary bugs around them.