Skip to content

Hallucination Prevention

Verify AI-generated code against your indexed codebase — catch fake imports, phantom APIs, and wrong signatures before they ship.

AI agents hallucinate. They invent function signatures, import modules that don’t exist, and reference APIs that were deprecated three versions ago. Nella’s indexing and search system helps prevent these issues by grounding AI agents in your actual codebase.

The Problem

Without codebase context, AI-generated code often contains:

  • Phantom importsimport { formatDate } from './utils' where formatDate doesn’t exist
  • Wrong signatures — Calling getUser(id, options) when the real signature is getUser(id)
  • Deprecated APIs — Using request.body when you’ve migrated to request.json()
  • Type mismatches — Passing a string where the codebase expects number
  • Non-existent symbols — Referencing classes, types, or constants that were never defined

How Nella Solves It

Nella indexes your codebase and provides semantic search so AI agents can look up real symbols, types, and patterns before generating code:

nella_index → Build codebase index → nella_search → Agent gets real context → Generates grounded code

How Indexing Prevents Hallucinations

  1. Import verification — Agents can search for real module paths and exports before writing imports
  2. Symbol discovery — Agents can look up actual function names, classes, and types in your codebase
  3. API patterns — Agents can find real function signatures and usage patterns
  4. Type definitions — Agents can cross-reference existing type definitions before creating new ones

Grounding via RAG

The quality of hallucination prevention depends on your index. Keep your index fresh:

  • Auto-index on change: Enable indexOnChange in workspace config
  • File watching: FileWatcher detects changes and triggers incremental re-indexing
  • Force re-index: Call nella_index with force: true after major refactors

See RAG & Indexing for full indexing documentation.

Best Practice

Use nella_search before generating code that references existing modules or APIs. Looking up real symbols takes seconds and prevents phantom imports and wrong signatures.