StackDX AI Queries

StackDX AI is a powerful tool that lets you query our core datasets with natural language. With correct prompts, you can construct complex queries and get detailed reports in a matter of seconds, which was previously unattainable with traditional user interfaces.

Datasets currently supported: Canadian and US wells, pipelines, facilities, mineral rights, crown mineral activity, and surface dispositions.

Getting started

The quickest way to open StackDX AI interface is the Ctrl + ~ shortcut (Cmd + ~ on MacOS). Additionally, this shortcut allows you to instantly switch back and forth between your workspace and the chat.

Once the chat is open, enter an actionable prompt/question that specifies which dataset you are querying (e.g. wells) and what data you are after. StackDX AI will not be able to provide meaningful answers for questions that are too generic. For example, instead of asking "How do I query by licensee?" you can say:

Find all wells licensed to Tourmaline.

You can query any data that's available in the table and on the map but detailed info such as well completions history is currently not available. Note that the assistant does not have any context about your workspace so you'll need to provide it with input data directly. For example, instead of asking "What producing formations my list is in?" you can say:

What producing formations are these wells in?
100022705212W500
100012705212W500
100013405212W500
...

How it works

Behind the scenes, StackDX AI leverages an LLM to perform the following operations for every user prompt:

1

Determine dataset

Determine which dataset should be queried.

2

Build SQL

Build an SQL query whose output should satisfy the user's request. If the query includes all columns, it will be visualized on the map directly and the processing stops here. If the resulting query fails during execution, StackDX AI will make up to 2 attempts to rewrite it and retry.

3

Aggregate & summarize

If the request required some form of data aggregation, pass the first 50 results from the output back into the model to summarize it in a formatted text response. This result will only show up in your chat and won't be displayed on the map.

How to use

The SQL generation step produces its full introspection which you can access by clicking the "See technical details" button. If you spot an error or an incorrect assumption in the model's approach, you can guide it to correct itself in a follow-up message. For example:

User prompt:

Calculate mean recent oil production of all Tourmaline's wells.

Assistant reply (example):

SELECT AVG(recent_oil) AS mean_recent_oil FROM sql_table WHERE
LOWER(licensee::text) ILIKE '%tourmaline%';

...

The mean recent oil production of all Tourmaline's wells is approximately 3.52 cubic meters per month.

Follow-up user prompt:

Exclude all zero values from your calculation.

Assistant reply (example):

SELECT AVG(recent_oil) AS mean_recent_oil FROM sql_table WHERE
LOWER(licensee::text) ILIKE '%tourmaline%' AND recent_oil > 0;

...

The mean recent oil production of all Tourmaline's wells, excluding zero values, is approximately 101.01 cubic meters per month.

Note that StackDX AI currently has very limited access to production data: only "recent" fields for the latest monthly volumes and "cumulative" fields are available.

For data aggregation queries, you can specify the exact format you'd like to receive the data in. Only text-based formats are supported. For example:

User prompt:

Get top 10 wells by cumulative gas production and output them as a CSV with UWI, Licensee, and production columns.

Assistant reply (example text + CSV):

Here are the top 10 wells by cumulative gas production, along with their UWI, licensee, and cumulative production values. The data is also formatted as a CSV for your convenience:

UWI,Licensee,Cumulative Gas (e3m3)
102112204416W500,Tidewater Midstream and Infrastructure Ltd.,9526807
100092403610W500,Cavvy Production Ltd.,9332082
1W0120900330W400,Shell Canada Limited,9215807
...

Note that all textual responses are limited to a maximum of 50 results for cost and performance reasons.

Technical users can leverage the full spectrum of Polars SQL SELECT functionality by explicitly instructing StackDX AI to include certain expressions. For example, to find all wells whose licensees consist of exactly 8-character long words:

User prompt:

Find all wells whose licensees match the following regex: `^(?:[^[:space:]]{8})(?:[[:space:]]+[^[:space:]]{8})*$`

Assistant reply (example):

_Retrieves 15 wells licensed to Paterson Theodore, Crawford Sawmills, and Novacorp._

While it is trivial for StackDX AI to match all company names that are exactly 8 characters long, it struggles to come up with the correct syntax to match names with multiple conforming words. An explicit instruction above helps it overcome this limitation.

Calculations and conversions

You can ask the assistant to run mathematical operations on the data. Some common conversions are supported out of the box: you can ask for production volumes in BOE, convert monthly values to daily, or request aggregation results in imperial units. For more complex or ambiguous conversions it may be beneficial to include the formulas in your prompt:

User prompt:

Find top 3 active wells in Montney formation by recent GOR. Output as a table with UWI, Field, and GOR in scf/stb. Calculate GOR as 35,315 e3m3/6.2898 m3 * gas/oil. Exclude all wells whose oil or gas volumes are zero.

Assistant reply (example table):

UWI
Field
GOR (scf/stb)

100010707507W600

LA GLACE

7,009,884.5

103161507601W603

PEORIA

1,809,787.375

100110207721W500

GIROUXVILLE EAST

1,265,541.125

StackDX AI also supports simple geographic queries. You can always refine the results by providing more technical instructions as a follow-up:

User prompt:

Find all wells in a 5 km radius around 102160207808W600.

Assistant reply (example):

_Retrieves 181 wells centered on 102/16-2-78-8W6/00 bottom location via flat-earth distance approximation._

Follow-up user prompt:

Could you recalculate using Haversine formula?

Assistant reply (example):

_Retrieves the same 181 wells by applying Haversine formula._

Handling errors (expandable)

Troubleshooting: Response error and complex prompts

If you get a Response error message, your prompt might have been too complex to handle with a single query. Try splitting it up into several prompts by manually passing the results from previous queries. For example:

Single complex prompt:

Find the company with the most wells in BC and calculate its total recent oil production across all their wells in Canada.

Can be split up into two separate prompts:

First:

Find the company with the most wells in BC.

Assistant reply (example):

The company with the most wells in British Columbia (BC) is Canadian Natural Resources Limited, with a total of 11,258 wells.

Second:

Find total recent oil production of all CNRL's wells.

Assistant reply (example):

The total recent oil production from all wells operated by Canadian Natural Resources Limited (CNRL) is approximately 2,175,774.5 m³.

Curiously, if you try the example above, the "bad" prompt is still likely going to work. However, due to the inherent inconsistent behaviour of GPT-based LLMs, we generally recommend constructing simpler queries whenever possible. This reduces the likelihood of errors which cause StackDX AI to perform multiple retries and makes it easier for you to debug the results.

Stack tokens (expandable)

How tokens are consumed and checking usage

Every StackDX AI request expends a certain amount of Stack tokens. The exact amount depends primarily on the dataset you are querying (wells use up the most) and the length of your current chat history. Conversely, the length or the wording of your prompts has almost no measurable effect. Once your usage reaches 1 million tokens your further access will be limited until the next calendar month. Contact us at [email protected] to request more!

You can check your current usage by running /gpt-usage command in chat. If you no longer need previous context for your next prompt, you can clear your chat history by refreshing the page or by running /clear command.

Here's what typical usage looks like:

Prompt
Tokens used

Find all crown mineral activities approved in 2025.

3,000

Find all wells licensed to Tourmaline drilled since 2020.

4,800

Which formation has wells with the highest average TMD?

5,100

List the largest companies in Alberta by number of wells and format them as a table.

7,200

Overly complex queries may cause StackDX AI to perform multiple retries (and even fail after 3 unsuccessful attempts) which increase usage substantially.

We'd love to hear from you!

If you have any questions or feedback about StackDX AI, send us an email to [email protected]. We are also happy to hear if you found this article helpful or if we missed something you'd like us to cover.