All posts

How to Query DynamoDB Using AI

DynamoDB's query model is powerful — but the SDK interface is verbose. Writing KeyConditionExpression, FilterExpression, and ExpressionAttributeValues by hand for every question is time-consuming, error-prone, and requires you to remember which attributes are reserved words.

AI-powered querying lets you describe what you want in plain English and have the DynamoDB operation generated automatically. This guide explains how it works, what it can handle, and how to use Insight O' Mate — a privacy-first AI database assistant for NoSQL databases.


What is AI DynamoDB querying?

It is the process of translating a plain-English question into a DynamoDB SDK operation — including the correct KeyConditionExpression, FilterExpression, ExpressionAttributeValues, and ExpressionAttributeNames — without you writing them by hand.

For example:

"Get all orders for customer 'user-123' placed in the last 30 days, sorted by date."

becomes:

const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);

const params = {
  TableName: "orders",
  KeyConditionExpression:
    "customerId = :cid AND createdAt >= :since",
  ExpressionAttributeValues: {
    ":cid": { S: "user-123" },
    ":since": { S: thirtyDaysAgo.toISOString() },
  },
  ScanIndexForward: false,
};

const result = await dynamoDB.query(params).promise();

How the translation works

1. Table and attribute detection. Insight O' Mate reads your DynamoDB table names and attribute names using your AWS credentials. Your item values are never read.

2. Query generation. Your prompt and the table/attribute schema are sent to a stateless NLP engine. The engine determines whether to use GetItem, Query, or Scan and generates the complete SDK parameters.

3. Local execution. The operation runs on your machine via the AWS SDK. Your DynamoDB data never passes through any Insight O' Mate server.


Example queries and generated DynamoDB operations

GetItem — single item lookup

Prompt: Get the product details for product ID "prod-789".

const params = {
  TableName: "products",
  Key: {
    productId: { S: "prod-789" },
  },
};

const result = await dynamoDB.getItem(params).promise();

Query — partition key + filter

Prompt: Find all failed payments for user "user-456" in the last 7 days.

const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);

const params = {
  TableName: "payments",
  KeyConditionExpression: "userId = :uid",
  FilterExpression:
    "#status = :failed AND createdAt >= :since",
  ExpressionAttributeNames: {
    "#status": "status",  // 'status' is a DynamoDB reserved word
  },
  ExpressionAttributeValues: {
    ":uid": { S: "user-456" },
    ":failed": { S: "failed" },
    ":since": { S: sevenDaysAgo.toISOString() },
  },
};

Scan with filter

Prompt: Find all products in the 'Electronics' category under $50.

const params = {
  TableName: "products",
  FilterExpression: "category = :cat AND price < :maxPrice",
  ExpressionAttributeValues: {
    ":cat": { S: "Electronics" },
    ":maxPrice": { N: "50" },
  },
};

Count items

Prompt: How many active subscriptions are there?

const params = {
  TableName: "subscriptions",
  FilterExpression: "#status = :active",
  ExpressionAttributeNames: {
    "#status": "status",
  },
  ExpressionAttributeValues: {
    ":active": { S: "active" },
  },
  Select: "COUNT",
};

DynamoDB-specific handling

Insight O' Mate handles several DynamoDB-specific concerns automatically:

Reserved words

DynamoDB has hundreds of reserved words (name, status, size, type, etc.). Insight O' Mate automatically wraps them in ExpressionAttributeNames placeholders so queries don't fail at runtime.

Operation selection

The AI chooses between GetItem, Query, and Scan based on your question:

  • Exact primary key lookup → GetItem
  • Partition key specified → Query
  • No key specified → Scan (with a note that Scan is expensive on large tables)

Data type marshalling

DynamoDB requires typed attribute values ({ S: "..." }, { N: "..." }, { BOOL: true }). Insight O' Mate infers the correct types from your schema.


Supported DynamoDB operations

OperationDescription
GetItemSingle item by primary key
QueryItems by partition key + optional sort key range
Scan with FilterExpressionFull table scan with filters
SELECT COUNTItem count via Scan

Not generated: PutItem, UpdateItem, DeleteItem, BatchWriteItem. Read-only by design.


Privacy and security

  • Your AWS credentials are stored in your OS keychain — never transmitted
  • Your DynamoDB item values never leave your machine
  • Only your prompt and table/attribute names are sent to the NLP engine
  • The NLP engine is stateless — no prompts are logged

Setting up DynamoDB with Insight O' Mate

  1. Download Insight O' Mate
  2. Create an IAM user with AmazonDynamoDBReadOnlyAccess policy
  3. Generate an access key and secret key
  4. In the app, go to Connections → Add DynamoDB → enter your AWS credentials and region
  5. Type your first question

Using a read-only IAM role is strongly recommended to prevent any accidental writes.