Skip to main content
All CollectionsSnowflake AI agentsUsing Lang
Creating an SQL view for your AI Agent
Creating an SQL view for your AI Agent

Share data with your AI Agents by creating and sharing access to a view

Updated over a week ago

In order for AI Agents to generate insights you will need to provide them with read access to a SQL view containing the unstructured text data generated by your users, such as support tickets, call transcripts, or survey responses.

🀚 The view must have AT LEAST the following columns in order to work:

  • id: The id of the document (ticket, survey, etc.)

  • text: The unstructured text to be analyzed

  • creation_date: The date of creation of the unstructured text

  • user_id: The id of the user that generated the unstructured text

Here is an example of a view created in Snowflake with the required format:​

-- Customize if needed
SET LANGAI_APP_NAME = 'LANGAI_APP';

-- Example of a view creation. Customize it to your data structure.
CREATE OR REPLACE VIEW $LANGAI_APP_DB.PUBLIC.$VIEW_NAME(
ID,
TEXT,
CREATION_DATE,
USER_ID,
PLAN
) as SELECT id, text as text, creation_date, user_id, plan
FROM LANGAI_DEMO.PUBLIC.CUSTOMER_REVIEWS;

--- Give the application access to the view
GRANT USAGE ON DATABASE "YOUR_DATABASE" TO APPLICATION IDENTIFIER($LANGAI_APP_NAME);

GRANT USAGE ON SCHEMA "YOUR_SCHEMA" TO APPLICATION IDENTIFIER($LANGAI_APP_NAME);

GRANT SELECT ON VIEW "YOUR_VIEW" TO APPLICATION IDENTIFIER($LANGAI_APP_NAME);

The USAGE privilege is required on the parent database and schema. This privilege doesn't provide SELECT access to the database rows. Learn more here.

Including additional columns as metadata

You may include additional columns that can be used by the AI agent to aggregate the insights generated. In the example above, the column called plan is not mandatory, but we included it so o the agent is able to group the insights by the user's subscription plan.

This is a preview of the view we created:
​

And this is how the plan column may be used as a filter for the insights:

If you have any question about creating and using views, please get in touch with your CSM.

Did this answer your question?