Chat with your SQLite database using Anthropic
Choose your LLM provider and database to generate ready-to-use code for your Vanna agent.
Install the Package
# Install Vanna with your selected dependencies (v2 branch)
pip install 'vanna[anthropic,fastapi] @ git+https://github.com/vanna-ai/vanna.git@v2'Configure Your LLM
# Set up Anthropic Claude as your LLM
from vanna.integrations.anthropic import AnthropicLlmService
llm = AnthropicLlmService(
    model="claude-sonnet-4-5",
    api_key="sk-ant-..."  # Or use os.getenv("ANTHROPIC_API_KEY")
)Configure Your Database
# Import SQLite tool
from vanna.tools import RunSqlTool
from vanna.integrations.sqlite import SqliteRunner
# Set up database connection
db_tool = RunSqlTool(
    sql_runner=SqliteRunner(database_path="./your_database.db")
)Configure Your Agent Memory
Agent memory allows your agent to learn from past interactions by storing successful question-SQL pairs (or really more generically question-tool-argument tuples). When users ask similar questions in the future, the agent can search its memory to find relevant examples, improving accuracy and reducing the need to regenerate SQL from scratch.
# Import agent memory tools
from vanna.tools.agent_memory import SaveQuestionToolArgsTool, SearchSavedCorrectToolUsesTool
from vanna.integrations.local.agent_memory import DemoAgentMemory
# Set up agent memory for learning from questions and SQL
agent_memory = DemoAgentMemory(max_items=1000)
save_memory_tool = SaveQuestionToolArgsTool(agent_memory)
search_memory_tool = SearchSavedCorrectToolUsesTool(agent_memory)Configure User Authentication
Define how users are identified and authenticated in your application. This example shows a simple cookie-based authentication system that assigns group memberships based on user email.
# Import user authentication classes
from vanna.core.user import UserResolver, User, RequestContext
# Create a simple user resolver
class SimpleUserResolver(UserResolver):
    async def resolve_user(self, request_context: RequestContext) -> User:
        user_email = request_context.get_cookie('vanna_email') or 'guest@example.com'
        group = 'admin' if user_email == 'admin@example.com' else 'user'
        return User(id=user_email, email=user_email, group_memberships=[group])
# Initialize the user resolver
user_resolver = SimpleUserResolver()Create Your Agent
# Import base classes
from vanna import Agent
from vanna.core.registry import ToolRegistry
from vanna.tools import VisualizeDataTool
# Register tools
tools = ToolRegistry()
tools.register_local_tool(db_tool, access_groups=['admin', 'user'])
tools.register_local_tool(save_memory_tool, access_groups=['admin'])
tools.register_local_tool(search_memory_tool, access_groups=['admin', 'user'])
tools.register_local_tool(VisualizeDataTool(), access_groups=['admin', 'user'])
# Create your agent
agent = Agent(
    llm_service=llm,
    tool_registry=tools,
    user_resolver=user_resolver
)Run the Server
# Run the server with FastAPI
from vanna.servers.fastapi import VannaFastAPIServer
server = VannaFastAPIServer(agent)
server.run()  # Access at http://localhost:8000Complete Code
Copy and paste this complete example to get started with your configuration:
# All imports at the top
from vanna import Agent
from vanna.core.registry import ToolRegistry
from vanna.core.user import UserResolver, User, RequestContext
from vanna.tools import RunSqlTool, VisualizeDataTool
from vanna.tools.agent_memory import SaveQuestionToolArgsTool, SearchSavedCorrectToolUsesTool
from vanna.servers.fastapi import VannaFastAPIServer
from vanna.integrations.anthropic import AnthropicLlmService
from vanna.integrations.sqlite import SqliteRunner
from vanna.integrations.local.agent_memory import DemoAgentMemory
# Configure your LLM
llm = AnthropicLlmService(
    model="claude-sonnet-4-5",
    api_key="sk-ant-..."  # Or use os.getenv("ANTHROPIC_API_KEY")
)
# Configure your database
db_tool = RunSqlTool(
    sql_runner=SqliteRunner(database_path="./your_database.db")
)
# Configure your agent memory
agent_memory = DemoAgentMemory(max_items=1000)
save_memory_tool = SaveQuestionToolArgsTool(agent_memory)
search_memory_tool = SearchSavedCorrectToolUsesTool(agent_memory)
# Configure user authentication
class SimpleUserResolver(UserResolver):
    async def resolve_user(self, request_context: RequestContext) -> User:
        user_email = request_context.get_cookie('vanna_email') or 'guest@example.com'
        group = 'admin' if user_email == 'admin@example.com' else 'user'
        return User(id=user_email, email=user_email, group_memberships=[group])
user_resolver = SimpleUserResolver()
# Create your agent
tools = ToolRegistry()
tools.register_local_tool(db_tool, access_groups=['admin', 'user'])
tools.register_local_tool(save_memory_tool, access_groups=['admin'])
tools.register_local_tool(search_memory_tool, access_groups=['admin', 'user'])
tools.register_local_tool(VisualizeDataTool(), access_groups=['admin', 'user'])
agent = Agent(
    llm_service=llm,
    tool_registry=tools,
    user_resolver=user_resolver
)
# Run the server
server = VannaFastAPIServer(agent)
server.run()  # Access at http://localhost:8000