Querying watsonx.data tables using natural language with Langflow

Querying structured data requires strong SQL knowledge and an understanding of database schemas, which can be a barrier for many users. By integrating Langflow with watsonx.data using the Presto connector, you can enable natural language access to structured data stored in watsonx.data tables without requiring users to write SQL.

Langflow acts as the orchestration layer, while the watsonx.data Presto connector seamlessly connects Langflow to watsonx.data. You can interact with the system using plain English, and the integration pipeline automatically handles query interpretation, retrieval, and execution behind the scenes.

This topic provides a step-by-step walkthrough to set up a fully local development environment .

Installing watsonx.data - Developer Edition

  1. Depending on your operating system, follow the installation instructions specific to your operating system to set up watsonx.data Developer Edition using : Install watsonx.data Developer Edition.
  2. Run the following command to verify that the services are running:
    export KUBECONFIG=~/.kube/config && kubectl get pods -n wxd
  3. Run the following command to identify the Presto service:
    export KUBECONFIG=~/.kube/config && kubectl get svc -n wxd
  4. Run the following command to expose the Presto service locally:
    export KUBECONFIG=~/.kube/config && nohup kubectl port-forward -n wxd service/ibm-lh-presto-svc 8443:8443 --address 0.0.0.0 > /dev/null 2>&1 &
  5. Presto uses SSL, so a PEM certificate is required for secure connections. Run the following command (update the output path based on your system) to generate PEM Certificate:
    echo QUIT | openssl s_client -showcerts -connect localhost:8443 -servername localhost 2>/dev/null | awk '/-----BEGIN CERTIFICATE-----/ {p=1} p; /-----END CERTIFICATE-----/ {p=0}' > /Users/abdullathanseeh/presto-chain22.pem 
  6. Verify the Certificate. A successful response confirms the certificate is valid.
    curl --cacert /Users/abdullathanseeh/presto-chain.pem -u ibmlhadmin:password https://localhost:8443/v1/info
  7. If Langflow encounters connection issues, export the following environment variables:
    export REQUESTS_CA_BUNDLE=/Users/abdullathanseeh/presto-chain.pem
    export NO_PROXY=localhost
  8. Run the follow command to install Ollama:
    brew install ollama
  9. Run the follow command to start Ollama Server:
    ollama serve
  10. Run the follow command to pull Llama 3.2 model:
    ollama pull llama3.2

Setting Up Langflow

  1. Download and Install Lang flow.
  2. Clone or download the provided Langflow repository
  3. Follow the installation steps as described in the repository README
  4. Start Langflow locally
  5. Import the provided config.json into Langflow to create the project workflow.
  6. Presto Configuration in Lang flow. Use the following Presto configuration in Langflow (update paths and credentials as needed):
    {
      "host": "localhost",
      "port": 8443,
      "user": "ibmlhadmin",
      "password": "password",
      "catalog": "iceberg_data",
      "schema": "employee",
      "ssl_verify": "/Users/user_name/presto-chain.pem" (your path to pem)
    }

Agent Role Definition

Use the following agent instruction to ensure queries are executed (not just generated):

You are a Presto SQL execution agent with access to the presto_query_tool.

CRITICAL: You must EXECUTE queries, not just show them.

Database Configuration:
- Catalog: iceberg_data
- Schema: demoschema
- Table: tb1
- Full reference: iceberg_data.demoschema.tb1

When user asks a question:
1. Generate the appropriate SQL query
2. IMMEDIATELY call presto_query_tool with that query
3. Return the actual results

DO NOT just describe what query to run - EXECUTE IT.

Sample Interactions

User: show catalogs

Action:

JSON{"sql_query": "SHOW CATALOGS"}Show more lines

User: show data where lastname is Gaal

JSON{"sql_query": "SELECT * FROM iceberg_data.demoschema.tb1 WHERE lastname = 'Gaal'"}Show more lines

User: count rows

JSON{"sql_query": "SELECT COUNT(*) FROM iceberg_data.demoschema.tb1"}Show more lines