vanna README

The project's README from github.com/vanna-ai/vanna. As one markdown file: README.md.

Vanna 2.0: Turn Questions into Data Insights

Natural language → SQL → Answers. Now with enterprise security and user-aware permissions.

Python License Code style: black

https://github.com/user-attachments/assets/476cd421-d0b0-46af-8b29-0f40c73d6d83

Vanna2 Demo


What's New in 2.0

🔐 User-Aware at Every Layer — Queries automatically filtered per user permissions

🎨 Modern Web Interface — Beautiful pre-built <vanna-chat> component

⚡ Streaming Responses — Real-time tables, charts, and progress updates

🔒 Enterprise Security — Row-level security, audit logs, rate limiting

🔄 Production-Ready — FastAPI integration, observability, lifecycle hooks

Upgrading from 0.x? See the Migration Guide | What changed?


Get Started

Try it with Sample Data

Quickstart

Configure

Configure

Web Component

<!-- Drop into any existing webpage -->
<script src="https://img.vanna.ai/vanna-components.js"></script>
<vanna-chat
  sse-endpoint="https://your-api.com/chat"
  theme="dark">
</vanna-chat>

Uses your existing cookies/JWTs. Works with React, Vue, or plain HTML.


What You Get

Ask a question in natural language and get back:

1. Streaming Progress Updates

2. SQL Code Block (By default only shown to "admin" users)

3. Interactive Data Table

4. Charts (Plotly visualizations)

5. Natural Language Summary

All streamed in real-time to your web component.


Why Vanna 2.0?

✅ Get Started Instantly

✅ Enterprise-Ready Security

User-aware at every layer — Identity flows through system prompts, tool execution, and SQL filtering Row-level security — Queries automatically filtered per user permissions Audit logs — Every query tracked per user for compliance Rate limiting — Per-user quotas via lifecycle hooks

✅ Beautiful Web UI Included

Pre-built <vanna-chat> component — No need to build your own chat interface Streaming tables & charts — Rich components, not just text Responsive & customizable — Works on mobile, desktop, light/dark themes Framework-agnostic — React, Vue, plain HTML

✅ Works With Your Stack

Any LLM: OpenAI, Anthropic, Ollama, Azure, Google Gemini, AWS Bedrock, Mistral, Others Any Database: PostgreSQL, MySQL, Snowflake, BigQuery, Redshift, SQLite, Oracle, SQL Server, DuckDB, ClickHouse, Others Your Auth System: Bring your own — cookies, JWTs, OAuth tokens Your Framework: FastAPI, Flask

✅ Extensible But Opinionated

Custom tools — Extend the Tool base class Lifecycle hooks — Quota checking, logging, content filtering LLM middlewares — Caching, prompt engineering Observability — Built-in tracing and metrics


Architecture

Vanna2 Diagram


How It Works

sequenceDiagram
    participant U as 👤 User
    participant W as 🌐 <vanna-chat>
    participant S as 🐍 Your Server
    participant A as 🤖 Agent
    participant T as 🧰 Tools

    U->>W: "Show Q4 sales"
    W->>S: POST /api/vanna/v2/chat_sse (with auth)
    S->>A: User(id=alice, groups=[read_sales])
    A->>T: Execute SQL tool (user-aware)
    T->>T: Apply row-level security
    T->>A: Filtered results
    A->>W: Stream: Table → Chart → Summary
    W->>U: Display beautiful UI

Key Concepts:

  1. User Resolver — You define how to extract user identity from requests (cookies, JWTs, etc.)
  2. User-Aware Tools — Tools automatically check permissions based on user's group memberships
  3. Streaming Components — Backend streams structured UI components (tables, charts) to frontend
  4. Built-in Web UI — Pre-built <vanna-chat> component renders everything beautifully

Production Setup with Your Auth

Here's a complete example integrating Vanna with your existing FastAPI app and authentication:

from fastapi import FastAPI
from vanna import Agent
from vanna.servers.fastapi.routes import register_chat_routes
from vanna.servers.base import ChatHandler
from vanna.core.user import UserResolver, User, RequestContext
from vanna.integrations.anthropic import AnthropicLlmService
from vanna.tools import RunSqlTool
from vanna.integrations.sqlite import SqliteRunner
from vanna.core.registry import ToolRegistry

# Your existing FastAPI app
app = FastAPI()

# 1. Define your user resolver (using YOUR auth system)
class MyUserResolver(UserResolver):
    async def resolve_user(self, request_context: RequestContext) -> User:
        # Extract from cookies, JWTs, or session
        token = request_context.get_header('Authorization')
        user_data = self.decode_jwt(token)  # Your existing logic

        return User(
            id=user_data['id'],
            email=user_data['email'],
            group_memberships=user_data['groups']  # Used for permissions
        )

# 2. Set up agent with tools
llm = AnthropicLlmService(model="claude-sonnet-4-5")
tools = ToolRegistry()
tools.register(RunSqlTool(sql_runner=SqliteRunner("./data.db")))

agent = Agent(
    llm_service=llm,
    tool_registry=tools,
    user_resolver=MyUserResolver()
)

# 3. Add Vanna routes to your app
chat_handler = ChatHandler(agent)
register_chat_routes(app, chat_handler)

# Now you have:
# - POST /api/vanna/v2/chat_sse (streaming endpoint)
# - GET / (optional web UI)

Then in your frontend:

<vanna-chat sse-endpoint="/api/vanna/v2/chat_sse"></vanna-chat>

See Full Documentation for custom tools, lifecycle hooks, and advanced configuration


Custom Tools

Extend Vanna with custom tools for your specific use case:

from vanna.core.tool import Tool, ToolContext, ToolResult
from pydantic import BaseModel, Field
from typing import Type

class EmailArgs(BaseModel):
    recipient: str = Field(description="Email recipient")
    subject: str = Field(description="Email subject")

class EmailTool(Tool[EmailArgs]):
    @property
    def name(self) -> str:
        return "send_email"

    @property
    def access_groups(self) -> list[str]:
        return ["send_email"]  # Permission check

    def get_args_schema(self) -> Type[EmailArgs]:
        return EmailArgs

    async def execute(self, context: ToolContext, args: EmailArgs) -> ToolResult:
        user = context.user  # Automatically injected

        # Your business logic
        await self.email_service.send(
            from_email=user.email,
            to=args.recipient,
            subject=args.subject
        )

        return ToolResult(success=True, result_for_llm=f"Email sent to {args.recipient}")

# Register your tool
tools.register(EmailTool())

Advanced Features

Vanna 2.0 includes powerful enterprise features for production use:

Lifecycle Hooks — Add quota checking, custom logging, content filtering at key points in the request lifecycle

LLM Middlewares — Implement caching, prompt engineering, or cost tracking around LLM calls

Conversation Storage — Persist and retrieve conversation history per user

Observability — Built-in tracing and metrics integration

Context Enrichers — Add RAG, memory, or documentation to enhance agent responses

Agent Configuration — Control streaming, temperature, max iterations, and more


Use Cases

Vanna is ideal for:


Community & Support


Migration Notes

Upgrading from Vanna 0.x?

Vanna 2.0 is a complete rewrite focused on user-aware agents and production deployments. Key changes:

Migration path:

  1. Quick wrap — Use LegacyVannaAdapter to wrap your existing Vanna 0.x instance and get the new web UI immediately
  2. Gradual migration — Incrementally move to the new Agent API and tools

See the complete Migration Guide for step-by-step instructions.


License

MIT License — See LICENSE for details.


Built with ❤️ by the Vanna team | Website | Docs | Discussions

vanna (vanna-ai/vanna)

Searching Database…

23.8K ·GitHub
archived
这是干什么的?Vanna 是一个开源的 Python 框架,用来和你的 SQL 数据库对话:用户用日常语言输入一个问题,就能得到 SQL、数据表、图表和一段自然语言总结,并且内置了按用户划分的权限控制。
它是一个 Python 库、一个现成的应用,还是两者都有?两者都有:既有一个可以接入 FastAPI 或 Flask 的 Python 后端,也有一个现成的前端 Web 组件,可以嵌到任何网页里(React、Vue 或纯 HTML),负责展示聊天界面、表格和图表。
我怎么把它跑起来?先用 Quickstart 在示例数据上试用,然后通过 Configure 连接你自己的数据库和大语言模型。生产环境方面,有一个完整的示例,演示如何把 Vanna 嵌入现有的 FastAPI 应用并使用你自己的登录鉴权。
我可以接入哪些大语言模型和数据库?它不绑定任何服务商:大语言模型方面支持 OpenAI、Anthropic、Ollama、Azure、Gemini、AWS Bedrock、Mistral 等;数据库方面支持 PostgreSQL、MySQL、Snowflake、BigQuery、Redshift、SQLite、Oracle、SQL Server、DuckDB、ClickHouse 等等。
这个项目还在积极维护吗?在使用之前有一点值得注意:GitHub 仓库已经被归档,变成了只读状态,不再接受任何改动。README 上仍然写着可以通过 [email protected] 获取企业支持,但建议先核实一下现状。
我能把它部署在自己的服务器上并使用本地模型吗?可以——它运行在你自己的 FastAPI 或 Flask 应用里,如果你想让大语言模型完全留在本地,也支持 Ollama。README 里没有说明数据保留政策。
用户提问的时候实际能看到什么?五样东西实时流式展示:进度更新、一个 SQL 代码块(默认对非管理员用户隐藏)、一个可交互的数据表格、Plotly 图表,以及一段自然语言总结。
Vanna 是给谁用的?适合正在开发带自然语言界面的数据分析应用的团队、需要按用户划分权限的多租户 SaaS 产品,以及有审计要求的企业——任何想要现成的聊天界面加后端、而不想自己从零搭建的人都用得上。
按用户过滤数据在底层是怎么实现的?你的 User Resolver 会从请求中提取身份信息(cookies、JWT、OAuth 令牌);这些信息会贯穿系统提示词、工具执行和 SQL 过滤,而且每一条查询都会按用户记录在审计日志里。
Creator
vanna-ai
Size
8.4 MB
Stars
23.8K
Age
3y
Commits · 90 Days