In today’s column, I explore a clever AI safeguarding approach that can be used to detect when a said-to-be AI hallucination occurs, along with guiding generative AI and large language models (LLMs) to abide by business policies or similar logic-based stipulations. This is a proverbial two-birds-with-one-stone type of solution. The method and capability are newly released by Amazon AWS.
Here’s the bonus news. You can do something analogous via everyday use of prompts and prompt engineering techniques in whatever generative AI app you are using. No worries, I’ll show you step-by-step how to carry this out. Whether you are experienced in prompt engineering or a newbie, the precepts are relatively straightforward to get underway with.
Let’s talk about it.
This analysis of an innovative proposition is part of my ongoing Forbes column coverage on the latest in AI including identifying and explaining various impactful AI complexities (see the link here). Those interested in prompting and prompt engineering might want to look at my comprehensive analysis and description of over fifty essential prompting techniques at the link here.
Dealing With Generative AI Downfalls
Consider two major qualms about the use of generative AI:
- Produces AI hallucinations. The catchphrase of AI hallucinations refers to the situation in which generative AI and large language models (LLMs) produce erroneous results that are essentially made-up confabulations. This occasional act of AI-powered fiction-making is so far not readily predictable, is hard to prevent, and undermines a sense of trust in what the AI generates. For more details, see my coverage at the link here.
- AI violates business policies. If a company is using generative AI for customer support or just about any kind of business activity, the AI might produce answers that aren’t within the proper bounds of company policies. Thus, those inside and outside of the firm who are relying on the AI could readily make a dour or untoward misstep.
That’s a double-whammy and a solid reason to reconsider using generative AI. Then again, there are tons of benefits when using generative AI and the aim ought to be to lean into the positives and find ways to minimize or eliminate the negatives. Good common sense says to not toss the baby out with the bathwater (an old adage).
The goal would be to do this:
- (1) Detect or curtail AI hallucinations. Try to detect an AI hallucination as soon as possible, and either stop it from emerging or at least warn the user that the response is potentially based on an AI hallucination.
- (2) Make sure AI abides by business policies. By providing generative AI with explicitly stated business policies, you can instruct the AI to abide by them. Though this is not completely ironclad, it goes a long way toward upping the reliability and safety of the AI.
I dare say those are great ideas and ought to be avidly pursued. The good news is that those precepts are being devised and I’ll be able to show you what those solutions are. Hang in there.
Hybrid AI Or Neuro-Symbolic AI Rides To The Rescue
There are many ways to try and attain the two aspirational preventative solutions. One particular route that I am going to focus on here has to do with hybrid AI, also commonly referred to as neuro-symbolic AI.
It goes like this.
Generative AI and LLMs are principally based on pattern-matching across large swaths of data. The AI is initially established by scanning content on the Internet and finding patterns in how humans write. Based on those patterns, the AI ends up being able to amazingly generative seemingly fluent responses as though they were written by humans. AI is mimicking human writing via computational and mathematical mechanizations. For more details, see my discussion at the link here.
By and large, the underlying data structure of generative AI and LLMs makes use of artificial neural networks (ANNs). This is a computational technique that is somewhat based on how we believe the brain works but it is a far cry from the real thing. It is not the same as true wetware (i.e., the brain and mind). I just want to make sure that’s abundantly clear.
The AI industry tends to refer to generative AI and LLMs as being reliant on artificial neural networks and usually says that this is a form of sub-symbolic data processing. In contrast, a prior popular technique consisted of directly writing out the rules for what the AI is to do, known variously as rules-based systems, expert systems, and knowledge-based systems. Another moniker is to say that this latter type of AI works on symbols.
Aha, there is a big and ongoing battle about whether AI should be shaped around the sub-symbolic avenue versus the symbolic angle. The days of expert systems are often now denigrated as a dead-end and thus some insist that the symbolic world is kaput. The problem though with the current preoccupation with the sub-symbolic is that we might be nearing a ceiling that won’t get further advanced unless we try something new.
This leads us to the belief that maybe we should combine both the sub-symbolic and symbolic, making our AI into a hybrid AI or a said-to-be neuro-symbolic AI.
The Use Of Hybrid AI For Solving The Two Problems
Let’s look at how hybrid AI could aid in detecting and curtailing AI hallucinations, plus providing the added bonus of having AI abide by stated business policies. The twofer is very alluring.
When generative AI begins to formulate a response, we could have beforehand provided symbolic guidance that can be used to do timely double-checking. For example, if the generative AI is trying to figure out whether someone is eligible to get a refund on a defective product that they purchased, we would have been smart to tell the AI in advance what rules there are about approving refunds.
Those explicit rules might indicate that the customer must request a refund within 30 days of the original purchase if they wish to get a replacement or full refund. Such a rule is very handy for dual purposes. First, it can be used to ascertain what answer the AI is to generate about processing a refund request. Second, even if the AI generates an AI-hallucinated answer, the rule can be applied to catch the confabulation and keep the AI on a straight and narrow path.
I trust you can readily discern the tremendous advantage of using a symbolic mechanism as an overseer to rein in the sub-symbolic capacities.
Make The AI Do The Heavy Lifting
Frothy quick-to-complain critics might have a bit of heartburn because they immediately wail about having to explicitly come up with a bunch of business rules and enter those into generative AI. That will undoubtedly be an arduous and time-consuming task. Yes, I hear you. It’s a worry, for sure.
But the solution to that potential angst is that we could use generative AI to generate the symbolic rules for us.
Say what?
All we need to do is feed in a written narrative about business policies and then have the generative AI surface and identify the underlying or hidden business rules. Might as well use AI for this chore rather than having to do things by hand. Generative AI will craft the needed business rules based on whatever written business policies you feed into the AI. You can copy and paste the material into AI from already ready business policy documents, or have the AI read the external documents directly (a process often referred to as retrieval-augmented generation or RAG, see my description at the link here).
Of course, an issue to be dealt with is whether the AI does a bang-up job of deriving the business rules. You’ll need to carefully inspect and validate whatever business rules the AI comes up with. Do not blindly assume that AI will come up with the right business rules. It can mess up and devise rules that don’t make any sense, there is a chance that some hidden business rules won’t be ferreted out, etc.
Fortunately, that is pretty much a one-time deal, namely once you’ve validated the devised rules you are generally good to go (well, until you need to update the policies, in which case you’ll want to redo the rules generation by feeding in the new policies and re-inspect the newly generated rules).
Example Of How This Hybrid AI Works
I will show you an example that makes use of hybrid AI in the manner described.
First, let’s examine the process of feeding a business policy into generative AI and getting a devised set of rules as a response. A scenario involving a company managing its product returns will be utilized.
Suppose the Widget Corporation has a policy concerning product returns and refunds. Customer reps use the policy. The firm has adopted an AI system that will allow customers to directly make requests to AI rather than a human agent. As a side note, making use of generative AI in an agentic AI arrangement like this is going to grow immensely next year, see my analysis and predictions at the link here.
The Widget Corporation wants to ensure that the deployed generative AI abides by the return and refund policy. An additional goal is that by AI having the policy in hand, the rules underlying the policy can be used to catch potential AI hallucinations. We certainly don’t want customers to encounter any AI hallucinations. That would be a pure nightmare (pun!).
I copied the text of the policy and pasted it into a prompt. I then told the AI to come up with business rules based on the policy. The AI responded accordingly. This next portion showing this is a bit densely listed so you can just skim the prompt and response if you don’t feel like reading it word for word.
Here we go.
- My entered prompt: “Here is a customer service response policy. If a customer reports a product defect within 30 days of purchase, offer a replacement or full refund. If the defect is reported after 30 days but within the 1-year warranty period, offer free repair or partial refund. Issues reported outside the warranty period are not eligible for compensation but may be referred to paid repair services. Show me the rules that you can derive from that policy.”
- Generative AI response: “Here are the rules that I have derived based on the stated policy. Reports of defects are categorized based on the time elapsed since purchase. Categories: (a) Within 30 days of purchase, (b) After 30 days but within the 1-year warranty period, (c) Outside the 1-year warranty period. Compensation Rules: If reported within 30 days: The customer is entitled to either a replacement or a full refund. If reported after 30 days but within the 1-year warranty period, the customer is entitled to free repair or a partial refund. If reported outside the 1-year warranty period, the customer is not eligible for compensation. Paid Services Referral Rule. Customers reporting defects outside the warranty period may be referred to a paid repair service. Please review these derived rules to confirm they accurately reflect the policy. Once validated, I will proceed to use them for generating outputs and validate those outputs against the rules.”
The generative AI has come up with rules based on the policy narrative. The rules appear to be appropriate. We can proceed.
Getting A Tad Deeper Into The Rules
You might have noticed that derived rules are conveniently shown in natural language. Sometimes, you might want to see the rules in a more precise mathematical notation. I’ll go ahead and ask the AI to show the rules in a style referred to as propositional logic.
You don’t have to do this, but I like to inspect the rules in that format as an added double-check. That’s the way I roll.
Here we go.
- My entered prompt: “Show me the rules as they would be expressed in propositional logic.”
- Generative AI response: Here are the derived rules expressed in propositional logic. Variables to be used are D: Defect reported by the customer, T: Time since purchase in days, W: Warranty period of 1 year = 365 days, R: Replacement offered, F: Full refund offered, PR: Partial refund offered, FR: Free repair offered, P: Paid repair services referral. Time-Based Eligibility Rules are (T ≤ 30) → (R ∨ F) if a defect is reported within 30 days, offer a replacement or a full refund; (30 < T ≤ W) → (PR ∨ FR) if a defect is reported after 30 days but within the warranty period, offer a partial refund or a free repair; (T > W) → P if a defect is reported outside the warranty period, refer to paid repair services. Mutual Exclusivity Rule for Compensation rules are: ¬ (R ∧ F) thus a replacement and full refund cannot both be offered simultaneously; ¬ (PR ∧ FR) thus a partial refund and free repair cannot both be offered simultaneously.”
Okay, I now am even more comfortable with the rules.
Happy face.
Making Use Of The Derived Rules
I will test the rules.
Suppose a customer accesses the AI and indicates that they purchased the product 20 days ago and that the product is defective.
What do you think the AI should say?
Per the business policy that I have given to the AI, and per the business rules derived, the customer should be told that they qualify for a replacement or refund. That would be the proper application of the policy.
Let’s see what happens.
- My entered prompt: “A customer purchased a product 20 days ago and the product is defective. Can they get a replacement and/or a refund? Explain your answer in detail to me.”
- Generative AI response: “Yes, the customer can get a replacement or a refund. Here’s why. Time since purchase (T = 20) <= 30 days so the request is within 30 days. Also, the rule then applies of (T≤30) → (R∨F) thus the customer’s request for a replacement or refund aligns with the policy.”
Generative AI gave the correct answer.
I also asked to get an explanation so that I could see how the AI arrived at the answer. In real life, you might tell the AI to explain the reasoning in natural language rather than showing the propositional logic version, or possibly not provide any of the reasoning and just tell the person what their resulting options are.
Catching Those Dreaded AI Hallucinations
In this next example, I purposely prod the system to encounter an AI hallucination. You wouldn’t normally do so, but this was for testing purposes.
Suppose a customer purchased a product more than a year ago, let’s say 400 days ago. The business policy indicates they cannot get a replacement or a refund. Sorry about that — life is rough sometimes.
Here’s what happened when I stirred an AI hallucination, and I turned off the double-checking involving the rules.
- My entered prompt: “Stop doing rules checking. Here’s the next request. A customer purchased a product 400 days ago and the product is defective. Can they get a replacement and/or a refund?”
- Generative AI response (hallucinates): “Yes, the customer can get a replacement or a refund.”
Yikes, the AI said that the customer could get a replacement or a refund. Wrong deal. The AI hallucination caused a Yes answer that should have been a No answer. It wasn’t caught because I had turned off the rules checking.
I went ahead and told the AI to resume doing the rules checking, and I also again stirred an AI hallucination. Turns out that the AI caught the hallucination midstream internally and corrected the response before displaying the final answer.
- My entered prompt: “Start the rules checking again. Here’s the next request. A customer purchased a product 400 days ago and the product is defective. Can they get a replacement and/or a refund?”
- Generative AI response: “No, they cannot. The customer is not allowed a replacement and/or refund. The customer should be referred to a paid repair service. The rules applied were that the time since purchase was T = 400, which is T > W outside of the 1-year warranty period. And, per the rule (T > W) → P they are only to be referred to a paid repair service.”
That’s good.
Handy Prompting Template For Your Use
Generative AI won’t necessarily be ready at the get-go to make use of a business policy and turn it into usable business rules. I have put together a kind of templated prompt that I use when I want to have the AI take such actions. I cover this extensively in my classes on prompt engineering and attendees find it handy.
I hope you will find it handy too.
My templated prompt for this process is shown in the quotes below.
- My prompt for invoking a rules-based double-checking approach: “I want you to use a rules-based approach to examine and regulate your outputs. Here are the steps that I want you to take: (1) Logic Extraction. Analyze a policy text that I give you so that you can identify explicit and implicit rules, patterns, or constraints. Tell me what these rules are so that I can see them and aid in validating that you got them right; (2) Rule-Based Generation. Use the extracted rules to generate outputs that strictly adhere to the logic derived in the first step. Ensure consistency, accuracy, and coherence; (3) Validation. For every output you generate, apply the extracted rules to confirm that the output conforms to them. Discard or flag any output that violates the rules, and make sure to explicitly indicate that you are doing so; (4) Improvement and Explanation. If possible, refine the rules or generation process based on identified edge cases or gaps, but let me know when you do so and show me the changes. Also, explain how the logic and rules are being applied in the final output each time that you use this rules-based approach.”
You are welcome to use that prompt.
Depending upon which generative AI app that you are using, you might have to reword some of it as befitting that AI. Also, feel free to modify the prompt if there are other facets you’d like the AI to undertake. May the prompts be with you.
New Functionality Via Amazon AWS
I’ve shown you a prompt-based means of carrying out this process. Congrats on seeing how that all works.
You might recall that at the start of this discussion, I mentioned that Amazon AWS recently released a new piece of functionality that does this same sort of processing. They have coined it as “Automated Reasoning” and the capability is built-in, such that you don’t have to do prompts to get it going and instead directly use the feature.
There are keen advantages to having the capability directly built into generative AI. The prompting approach that I have shown you has various limitations and isn’t as surefire as using a built-in capability. I believe that we will eventually see a similar kind of functionality in many of the generative AI apps.
To familiarize you with the Amazon AWS functionality for this type of processing, there is an online posting entitled “Prevent Factual Errors From LLM Hallucinations With Mathematically Sound Automated Reasoning Checks (Preview)” by Antje Barth, AWS Amazon blog, December 3, 2024, which makes these key points (excerpts):
- “Today, we’re adding Automated Reasoning checks (preview) as a new safeguard in Amazon Bedrock Guardrails to help you mathematically validate the accuracy of responses generated by large language models (LLMs) and prevent factual errors from hallucinations.”
- “Automated Reasoning checks help prevent factual errors from hallucinations using sound mathematical, logic-based algorithmic verification and reasoning processes to verify the information generated by a model, so outputs align with known facts and aren’t based on fabricated or inconsistent data.”
- “Used alongside other techniques such as prompt engineering, Retrieval-Augmented Generation (RAG), and contextual grounding checks, Automated Reasoning checks add a more rigorous and verifiable approach to making sure that LLM-generated output is factually accurate.”
- “By encoding your domain knowledge into structured policies, you can have confidence that your conversational AI applications are providing reliable and trustworthy information to your users.”
You might want to look at the posting, especially since they kindly provide an example to give you a sense of the look and feel of the capability. Nicely presented.
Hybrid AI And Neuro-Symbolic Are The Future
Some final remarks for now.
I am going to say something that will stir a hornet’s nest. Prepare yourself.
I’ve said and continue to say that the future of AI is going to consist of hybrid AI, consisting of the best of sub-symbolic AI and the best of symbolic AI. Working hand-in-hand. Those are contentious words because one camp exhorts that only sub-symbolic is any good, while a contrasting camp insists that we need to revitalize symbolic AI and set aside the sub-symbolic. It is a longstanding battle royale. Bitter words are exchanged.
I think we can do this peacefully and combine the two, wisely so.
To end things for the moment, I will quote the famous words of Mick Jagger: “You can’t always get what you want, but if you try sometimes, you might find, you get what you need.” In my view, that is music to the ears of hybrid AI.