write-tenant-isolated-queries

Enforce tenantId in Cosmos DB partition-key queries across CRUD operations.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/Edgame2/castiel2 --skill write-tenant-isolated-queries
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-tenant-isolated-queries
Source: https://github.com/Edgame2/castiel2/tree/main/.cursor/skills/write-tenant-isolated-queries
Command: npx skills add https://github.com/Edgame2/castiel2 --skill write-tenant-isolated-queries

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Transforms database queries to include tenantId in partition keys, guaranteeing tenant isolation across multi-tenant Cosmos DB deployments.

Core Features & Use Cases

  • Enforces tenantId in all queries by including c.tenantId in the WHERE clause and using parameterized queries.
  • Uses container names derived from config to avoid hardcoding, ensuring consistent isolation boundaries.
  • Provides end-to-end guidance for Create, Read by ID, List with Filters, Update, and Delete with tenant isolation guarantees.

Quick Start

Rewrite your data access code so every query includes tenantId in the WHERE clause.

Frequently Asked Questions about write-tenant-isolated-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce tenant isolation in Cosmos DB queries?

Enforce tenant isolation in Cosmos DB queries by including c.tenantId in the WHERE clause of every operation. Use parameterized queries and ensure tenantId acts as the first parameter in your service methods.

What is the best way to structure multi-tenant queries for Cosmos DB CRUD operations?

The best way to structure multi-tenant queries is to pass tenantId as the first parameter in all service methods and embed it within the partition key WHERE clause. This guarantees isolation across Create, Read, Update, and Delete operations.

How does parameterized querying prevent tenant data leakage in multi-tenant applications?

Parameterized querying prevents tenant data leakage by binding tenantId as a filter parameter in the WHERE clause. This ensures Cosmos DB restricts query execution to the correct logical partition, isolating tenant data.

Can I use hardcoded container names for tenant isolation in Cosmos DB?

No, you should not use hardcoded container names for tenant isolation. Derive container names from configuration to maintain consistent isolation boundaries and prevent accidental cross-tenant access.

Do I need to include tenantId in partition key queries for Read by ID operations?

Yes, you need to include tenantId in partition key queries for Read by ID operations. Adding tenantId to the WHERE clause guarantees tenant isolation even when retrieving a specific document by its identifier.