This notebook provides a quick overview for getting started with Tableau.
OverviewTableau's VizQL Data Service (aka VDS) provides developers with programmatic access to their Tableau Published Data Sources, allowing them to extend their business semantics for any custom workload or application, including AI Agents. The simple_datasource_qa tool adds VDS to the Langchain framework. This notebook shows you how you can use it to build agents that answer analytical questions grounded on your enterprise semantic models.
Follow the tableau-langchain project for more tools coming soon!
SetupMake sure you are running and have access to:
Get started by installing and/or importing the required packages
Requirement already satisfied: regex>=2022.1.18 in /Users/joe.constantino/.pyenv/versions/3.12.2/lib/python3.12/site-packages (from tiktoken<1,>=0.7->langchain-openai->langchain-tableau) (2024.11.6)
Requirement already satisfied: httpcore==1.* in /Users/joe.constantino/.pyenv/versions/3.12.2/lib/python3.12/site-packages (from httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph->langchain-tableau) (1.0.7)
Requirement already satisfied: h11<0.15,>=0.13 in /Users/joe.constantino/.pyenv/versions/3.12.2/lib/python3.12/site-packages (from httpcore==1.*->httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph->langchain-tableau) (0.14.0)
Note you may need to restart your kernal to use updated packages
CredentialsYou can declare your environment variables explicitly, as shown in several cases in this doc. However, if these parameters are not provided, the simple_datasource_qa tool will attempt to automatically read them from environment variables.
For the Data Source that you choose to query, make sure you've updated the VizqlDataApiAccess permission in Tableau to allow the VDS API to access that Data Source via REST. More info here.
from langchain_openai import ChatOpenAI
from langchain_tableau.tools.simple_datasource_qa import initialize_simple_datasource_qa
from langgraph.prebuilt import create_react_agent
Authentication Variables
You can declare your environment variables explicitly, as shown in several cases in this cookbook. However, if these parameters are not provided, the simple_datasource_qa tool will attempt to automatically read them from environment variables.
For the Data Source that you choose, make sure you've updated the VizqlDataApiAccess permission in Tableau to allow the VDS API to access that Data Source via REST. More info here.
import os
from dotenv import load_dotenv
load_dotenv()
tableau_server = "https://stage-dataplane2.tableau.sfdc-shbmgi.svc.sfdcfc.net/"
tableau_site = "vizqldataservicestage02"
tableau_jwt_client_id = os.getenv(
"TABLEAU_JWT_CLIENT_ID"
)
tableau_jwt_secret_id = os.getenv(
"TABLEAU_JWT_SECRET_ID"
)
tableau_jwt_secret = os.getenv(
"TABLEAU_JWT_SECRET"
)
tableau_api_version = "3.21"
tableau_user = "joe.constantino@salesforce.com"
datasource_luid = (
"0965e61b-a072-43cf-994c-8c6cf526940d"
)
model_provider = "openai"
os.environ["OPENAI_API_KEY"]
tooling_llm_model = "gpt-4o-mini"
Instantiation
The initialize_simple_datasource_qa initializes the Langgraph tool called simple_datasource_qa, which can be used for analytical questions and answers on a Tableau Data Source.
This initializer function:
analyze_datasource = initialize_simple_datasource_qa(
domain=tableau_server,
site=tableau_site,
jwt_client_id=tableau_jwt_client_id,
jwt_secret_id=tableau_jwt_secret_id,
jwt_secret=tableau_jwt_secret,
tableau_api_version=tableau_api_version,
tableau_user=tableau_user,
datasource_luid=datasource_luid,
tooling_llm_model=tooling_llm_model,
model_provider=model_provider,
)
tools = [analyze_datasource]
Invocation - Langgraph Example
First, we'll initlialize the LLM of our choice. Then, we define an agent using a langgraph agent constructor class and invoke it with a query related to the target data source.
from IPython.display import Markdown, display
model = ChatOpenAI(model="gpt-4o", temperature=0)
tableauAgent = create_react_agent(model, tools)
messages = tableauAgent.invoke(
{
"messages": [
(
"human",
"what's going on with table sales?",
)
]
}
)
messages
Chaining
TODO.
API referenceTODO.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4