# AI use cases for Schemagate (ashishsinha1602/schemagate)

Repo: [ashishsinha1602/schemagate](https://github.com/ashishsinha1602/schemagate) | Use cases: 5 | Page: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/

schemagate is a Python library and local studio page that filters a text-to-SQL schema by the caller's grants, so restricted tables never reach the LLM prompt.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- See which tables a caller is blocked from: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/see-tables-hidden-from-a-caller/
- Select tables for one role on your own database: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/select-tables-for-a-role-on-your-database/
- Gate the schema inside a SQL agent's Python code: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/gate-schema-in-a-langchain-or-mcp-agent/
- Measure how many prompt tokens selection saves: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/measure-prompt-savings-on-a-schema/
- Tune table hints in the Studio page: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/tune-table-hints-in-the-studio-page/

## How to see which tables a caller is blocked from with Schemagate

Repo: [ashishsinha1602/schemagate](https://github.com/ashishsinha1602/schemagate) | Difficulty: Beginner | Time: 15 minutes | Basis: From the README

Compare the same question for two callers and confirm restricted tables leave the prompt, with no database needed.

**Who it is for:** A developer building a text-to-SQL agent who needs proof that a restricted table never reaches the model for a given role.

**The problem:** Schema selection often runs before identity is checked, so the model can be handed a table the caller cannot read and then returns a misleading empty answer.

**The outcome:** You see a restricted table absent for one caller and ranked first for a caller with the right role, with no database or model key.

### Steps

1. Run `pip install schemagate` to install the library.
2. Run `schemagate demo "salary by employee"` and confirm hr_compensation is absent from the result.
3. Run `schemagate demo "salary by employee" --principal okta:hr --role payroll` and confirm the table now appears first.
4. Run `schemagate demo "salary by employee" --prompt` if you want to read the DDL the model would receive. (inferred, check the README)

### Prompt to paste into your agent

```text
Install schemagate with pip, then run `schemagate demo "salary by employee"` and again with `--principal okta:hr --role payroll`. Report which tables appear in each result and confirm hr_compensation is absent for the first caller and present for the second.
```

### Caveat

The demo runs on the bundled 42-object sample schema, so the results show the mechanism but not how your own grants will behave until you run it against your database.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/see-tables-hidden-from-a-caller/

## How to select tables for one role on your own database with Schemagate

Repo: [ashishsinha1602/schemagate](https://github.com/ashishsinha1602/schemagate) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Run schema selection against a real Postgres database as a named principal and get the prompt fragment for that role.

**Who it is for:** A data team lead who wants to confirm that a finance user's text-to-SQL prompt only includes tables that user may read.

**The problem:** Without identity-aware selection, a finance question can pull in tables outside finance access, and row-level security then hides every row without telling the user why.

**The outcome:** You get the list of tables selected for the finance role on your database, with the prompt sized to those tables only.

### Steps

1. Run `pip install 'schemagate[postgres]'` to add the Postgres driver.
2. Run `schemagate select "revenue by month" --url postgresql://localhost/app --principal okta:jdoe --role finance` against your database.
3. Check that every table in the output is one the finance role is allowed to read.
4. Run the same command with a different `--role` value and compare the table lists.

### Prompt to paste into your agent

```text
Install schemagate with the postgres extra, then run `schemagate select "revenue by month" --url <postgres-url> --principal okta:jdoe --role finance`. Return the selected table names and state whether any table is one the finance role should not read.
```

### Caveat

The result is only as accurate as the grants Schemagate can see in your database and the roles you pass in, so check the output against your actual access rules.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/select-tables-for-a-role-on-your-database/

## How to gate the schema inside a SQL agent's Python code with Schemagate

Repo: [ashishsinha1602/schemagate](https://github.com/ashishsinha1602/schemagate) | Difficulty: Advanced | Time: 1 hour | Basis: From the README

Load a catalog, restrict a table to one role, and pass only the selected schema fragment into your agent prompt.

**Who it is for:** A developer shipping a LangChain or MCP SQL agent who must make sure the system prompt never names tables the caller cannot read.

**The problem:** Agent frameworks typically build the schema prompt before any access check, which leaks table names and structure to the model.

**The outcome:** Your agent's system prompt contains only the selected DDL, and a restricted table's name does not appear anywhere in the prompt text.

### Steps

1. Run `pip install schemagate` and install the driver extra for your database, such as `pip install 'schemagate[postgres]'`.
2. In Python, create the catalog with `Catalog().bootstrap("postgresql://localhost/app")` or load the bundled one with `demo_catalog()`.
3. Call `cat.restrict("hr_compensation", ["payroll"])` to limit that table to the payroll role.
4. Call `cat.select("revenue by month", top_k=6, principal=Principal("okta:jdoe", roles={"finance"}))` and pass `sel.prompt_fragment()` into your system prompt. (inferred, check the README)

### Prompt to paste into your agent

```text
Using the schemagate Python API, bootstrap a Catalog from <database-url>, restrict the table <restricted-table> to the role <role>, and select tables for the question <question> for a Principal with that role. Return sel.prompt_fragment() and confirm the restricted table name does not appear in it.
```

### Caveat

The README's example uses Catalog and Principal calls that you must verify against the installed version, since the library's documented API is what this depends on.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/gate-schema-in-a-langchain-or-mcp-agent/

## How to measure how many prompt tokens selection saves with Schemagate

Repo: [ashishsinha1602/schemagate](https://github.com/ashishsinha1602/schemagate) | Difficulty: Beginner | Time: 15 minutes | Basis: From the README

Compare the DDL a model gets with and without Schemagate for one question on the bundled schema.

**Who it is for:** A team lead estimating the token cost of a text-to-SQL agent before rolling it out on a large schema.

**The problem:** Pasting the whole schema into every prompt costs more as the schema grows, and the cost is hard to estimate without seeing the actual prompt.

**The outcome:** You see the reduced DDL for one question, with a token count compared against the full schema.

### Steps

1. Run `pip install schemagate` to install the library.
2. Run `schemagate demo "late shipments by carrier" --prompt` to print the DDL the model would receive.
3. Run `schemagate demo "which customers owe us money"` and note the objects count and approximate token figure shown.
4. Repeat with your own questions and compare against the full schema size.

### Prompt to paste into your agent

```text
Install schemagate, then run `schemagate demo "late shipments by carrier" --prompt` and `schemagate demo "which customers owe us money"`. Report the number of selected objects and the approximate prompt token count for each, and state the total object count of the bundled schema.
```

### Caveat

The savings figures in the README come from the test schemas and a built-in estimator, so your own schema and tokenizer will give different numbers.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/measure-prompt-savings-on-a-schema/

## How to tune table hints in the Studio page with Schemagate

Repo: [ashishsinha1602/schemagate](https://github.com/ashishsinha1602/schemagate) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Open the local Studio page, try questions, and add hints to steer selection toward the right tables.

**Who it is for:** A data analyst whose text-to-SQL agent keeps picking the wrong table for a business term.

**The problem:** A question can match a table with a similar name, so the agent answers from a draft or unrelated table.

**The outcome:** You get a hint attached to the table that the Studio page then uses to rank it, and you can see the change in what reaches the prompt.

### Steps

1. Run `pip install 'schemagate[postgres]'` to install the library with the Postgres driver.
2. Run `schemagate studio --url postgresql://localhost/app` to open the local Studio page.
3. Type a question that picks the wrong table and check which objects reach the prompt.
4. Add a hint for that table, then ask the question again and confirm the table selection changed.

### Prompt to paste into your agent

```text
Run `schemagate studio --url <postgres-url>`, ask the question <question>, add a hint to the table <table-name>, and re-run the question. Report which tables were selected before and after the hint and whether the target table now appears.
```

### Caveat

Hints change selection only for the database they are attached to, so test the result on the same URL your agent uses.

Risk, credentials: The database URL passed to the Studio command can contain a password, so avoid pasting it into shared shell history or screenshots.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/ashishsinha1602-schemagate/tune-table-hints-in-the-studio-page/
