[Python] How to train Vanna AI to distinguish between two similar tables and their column...

Discussão em 'Python' iniciado por Stack, Agosto 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am working with Vanna AI (text-to-SQL) and I have two problems regarding my database schema and how the model interprets it:

    Problem 1: Two similar tables

    I have two tables: SellingDocuments, BuyingDocuments

    Both tables have exactly the same column names (e.g. DocumentType, CustomerId, Date, etc.).

    When I train Vanna, it sometimes confuses the two tables and mixes them up in the generated SQL queries.

    Question: How can I train Vanna (or structure the training data / prompts) so that the AI clearly distinguishes between these two tables and doesn’t confuse them?

    Problem 2: Mapping natural language to column values

    Inside both tables, there is a column called DocumentType. This column can contain values such as:

    Order, Order Confirmation, Invoice

    When the user asks something like:

    "Show me all invoices from last month in SellingDocuments"

    I want Vanna to:

    Understand that "invoice" refers to the value "Invoice" inside the DocumentType column.

    Use the correct table (SellingDocuments or BuyingDocuments) depending on the user query.

    Question: How can I teach/train Vanna to correctly map these natural language terms (like "Order", "Invoice", etc.) to the corresponding values in the DocumentType column, while also choosing the right table?

    What I’ve tried

    Added descriptions for the tables and columns in the training step.

    Tried fine-tuning with example questions and answers, but Vanna still sometimes mixes the tables or ignores the DocumentType mapping.

    Desired outcome

    Queries should use the correct table (SellingDocuments vs. BuyingDocuments).

    Queries should correctly filter by DocumentType when the user uses natural terms like "invoice" or "order confirmation".

    Continue reading...

Compartilhe esta Página