Detect hallucinations
Despite these precautions, hallucinations can “slip through.” The good news: These are often easier to recognize in code than in applications. Finally, it is executable and can also be tested.
1. Evaluate AI code with AI
It may sound strange, but AI assistants are actually very good at examining AI-generated code for hallucinations.
For example, Daniel Lynch, CEO of marketing company Empathy First Media, suggests: “Write supporting documentation for the code so that the AI can evaluate it in a new instance – and determine whether it meets the requirements of the targeted use cases.”
2. Maintain human control
In the eyes of many IT and development professionals, human expertise is the last line of defense against AI hallucinations. Mithilesh Ramaswamy, senior engineer at Microsoft, also sees it as critical to success that human developers keep the reins: “AI should serve as a guide – not as a source of truth. Accordingly, you should view AI-generated code as a suggestion and not as a replacement for human expertise.”
However, this should not only apply to the programming work, but also to the code itself, as CTO Rehl suggests: “If you are unfamiliar with a code base, it can be difficult to spot hallucinations.”
The technology decision maker states that a close hands-on relationship with one’s own code is what helps.
3. Test code
Fortunately, tools and techniques that are already used in most companies can also detect AI hallucinations – to identify human errors.
“Development teams should continue to conduct pull requests and code reviews as if the code had been written by humans,” says Confluent expert Sellers. It is tempting for developers to use AI tools primarily to automate more and implement the continuous delivery approach – this is laudable, but it is also extremely important to prioritize appropriate quality assurance controls.
“It can’t be overstated how important it is to use good linting tools and SAST scanners throughout the development cycle,” says Brett Smith, Distinguished Software Developer at SAS. He adds: “IDE plugins, CI integrations and pull requests are the bare minimum to prevent hallucinations from making their way into production.”
According to Salesforce manager Banerjee, a mature DevOps pipeline, where every line of code is subjected to a unit test, is also essential: “The pipeline only advances the code to staging and production phases once tests and builds have passed.”
4. Highlight AI-generated code
To make code generated by AI more visible, Devansh Agarwal, machine learning engineer at AWS, has a trick up his sleeve: “Use the code review interface to highlight the parts of the codebase that are AI-generated.”
According to the ML expert, this not only helps detect hallucinations: “It can also be a great learning opportunity for everyone in the team. Sometimes these tools do great work that is worth imitating.”
