← Latest papers
💻 computer science

Influence of Prompt Engineering on Small Language Models for Guarded Query Routing

This paper demonstrates that prompt engineering techniques, particularly few-shot optimization and DSPy signatures, significantly enhance the guarded query routing performance of compact Small Language Models, enabling them to approach the accuracy of larger frontier models while maintaining low latency.

Original authors: Richard Šléher, William Brach, Kristián Košťál, Lukas Galke Poech

Published 2026-07-29
📖 7 min read🧠 Deep dive

Original authors: Richard Šléher, William Brach, Kristián Košťál, Lukas Galke Poech

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are running a busy, high-tech post office for a giant library of knowledge. Every day, millions of letters (queries) arrive, asking for help with everything from legal contracts to medical advice. But here's the catch: some letters are dangerous, some are nonsense, and some are just asking about things the library doesn't cover. If you send a dangerous letter to a librarian who specializes in medicine, you might get a bad answer or even a safety hazard. So, before any letter reaches a specialist, it must pass through a "Guardian" at the front door. This Guardian has two jobs: first, to decide if the letter is safe and belongs in the library at all; and second, if it is safe, to quickly figure out which specific expert (Law, Finance, or Healthcare) should read it.

For a long time, people thought you needed a massive, super-intelligent robot to be this Guardian because the job is tricky. But massive robots are slow, expensive, and hungry for electricity. This paper asks a fun question: Can we use smaller, cheaper, and faster "pocket robots" (called Small Language Models) to do this Guardian job? The catch is that these smaller robots sometimes get confused. They might be great at spotting nonsense, but when they see a real question, they get too shy to pick a specific expert, or they forget the rules of the game. The researchers wanted to see if we could teach these smaller robots to follow the rules better just by changing the instructions we give them, without having to rebuild the robots themselves.

The Guardian's Dilemma

In the world of artificial intelligence, we have these "Large Language Models" that are like brilliant, all-knowing wizards. They can write stories, solve math problems, and chat about anything. But they are heavy and slow. To make them useful for real-time tasks, we often put a "router" in front of them. Think of this router as a bouncer at a club. The bouncer has to decide two things instantly: "Is this person allowed in?" (Safety/Out-of-Distribution) and "Which VIP lounge should they go to?" (Intent/In-Distribution).

If the bouncer is too strict, they kick out good guests (rejecting valid questions). If they are too loose, they let in troublemakers (unsafe questions). The paper calls this "Guarded Query Routing." The goal is to find a bouncer that is fast, cheap, and accurate enough to keep the club safe while getting the right people to the right rooms.

The Experiment: Training the Pocket Robots

The researchers gathered 22 different "pocket robots" (Small Language Models) of various sizes, ranging from tiny ones with 270 million "brain cells" (parameters) to larger ones with 70 billion. They tested them on a special test called GQR-Bench, which is like a giant obstacle course filled with three types of valid questions (Law, Finance, Healthcare) and seven types of tricky, off-topic, or dangerous questions.

They measured the robots using a special score called the GQR-Score, which is a balance between how well they caught the valid questions and how well they rejected the bad ones. If a robot rejects everything, it gets a low score because it's useless. If it accepts everything, it also gets a low score because it's unsafe.

The Big Discovery: It's Not About Size, It's About Instructions

The first thing the team found was that size isn't everything. The biggest, most powerful robot (Gemma 3 27B) got a fantastic score of 96.01. But guess what? A much smaller robot (Qwen3.5 9B) got almost the same score (94.55) just by using a standard set of instructions. Even a mid-sized robot (Mistral 7B) did pretty well, scoring 81.79.

However, the tiny robots had a weird problem. They were too good at saying "No!" to everything. For example, the Granite 4 Tiny robot was so scared of making a mistake that it rejected 99.75% of all questions, including the good ones! It only managed to correctly identify valid questions 37.29% of the time. It was like a bouncer who decided the only safe way to run a club was to lock the doors and let no one in.

The Magic Fix: The "Example" Trick

The researchers wondered: "Can we fix these shy robots just by changing the instructions?" They didn't retrain the robots (which is like rebuilding their brains); instead, they used a technique called Prompt Engineering. This is like giving the robot a cheat sheet or a set of examples before it starts working.

They tried a few methods, but the results depended on the robot. The most effective method for the Granite 4 Tiny robot wasn't actually the "example" trick, but a simpler instruction format called the DSPy Baseline. This method stripped away the extra fluff and gave the robot a strict, bare-bones template. It went from a terrible score of 54.29 to a great 83.05. It stopped rejecting everything and started actually sorting the mail.

For other robots, like Mistral 7B, the "example" trick (called Few-Shot Prompting) was the real magic. Imagine you are teaching a new employee how to sort mail. Instead of just saying "Sort the mail," you show them three examples:

  1. "This letter is about a lawsuit -> Send to Law."
  2. "This letter is about stocks -> Send to Finance."
  3. "This letter is about a cat -> Send to the 'Reject' bin."

When they gave the Mistral 7B robot these examples, it jumped from 81.79 to 90.87. The Qwen3.5 9B robot also got even better with this method, reaching 95.74, which is almost as good as the giant robot, but it runs much faster.

The paper suggests that the problem wasn't that the small robots didn't know the answers; they just didn't know how to follow the rules of the game. The examples (or the strict template) showed them exactly what a correct answer looked like, and they instantly got the hang of it.

The Trade-Off: Speed vs. Accuracy

There is a small catch, though. When you give the robot a cheat sheet with examples, the message it has to read gets longer. This makes the robot slightly slower. The study found that using these examples made the robots take about 2 to 6 times longer to answer a single question. However, they were still incredibly fast (around 0.05 to 0.28 seconds per question), which is fast enough for most real-world apps.

The researchers also tried a more complex method called GEPA, which is like having a teacher robot rewrite the instructions automatically. But this didn't work as well as just giving the robot a few clear examples. In fact, for some of the smallest robots, the complex rewriting made things worse, causing them to get confused again.

What This Means for the Future

The main takeaway is that you don't always need the biggest, most expensive robot to be a good Guardian. A smaller, cheaper robot can do the job just as well if you give it the right instructions. Specifically, showing it a few examples (Few-Shot) helps it overcome its shyness and follow the rules, while for some very specific robots, a strict, bare-bones template works best.

However, the paper also warns that if a robot is too small (like the 0.8 billion parameter ones), even the best examples might not be enough to save it. And if a robot is already doing a great job, adding examples might not help much and could even slow it down unnecessarily.

In short, for building a safe and fast AI system, the secret sauce isn't just buying the biggest brain; it's knowing how to talk to the brain you have. A little bit of "prompt engineering" can turn a confused, over-cautious robot into a sharp, efficient guardian.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →