Natural-Language-to-SQL API
Turn plain-English questions into SQL automatically. Build text-to-database interfaces, India-native, billed in rupees, no international card.
Turn questions into queries
Most people in a company can describe what they want to know but can't write the SQL to get it. unoblox turns a plain-English question into a query against your schema — through one OpenAI-compatible endpoint, billed in rupees.
Why text-to-SQL
SQL is powerful but gatekept by syntax. A language model that's shown your schema can translate "how many customers signed up last month" into a working query, putting the database in reach of anyone who can type a question.
Best models
| Model | Input ₹/1M | Output ₹/1M | Fit |
|---|---|---|---|
| Qwen3 Max | ₹120.95 | ₹604.77 | Cost-effective for simple, repetitive queries |
| GPT-4.1 | ₹201.6 | ₹806.4 | Strong general SQL generation |
| Claude Opus | ₹504 | ₹2520 | Best for multi-table joins and complex logic |
Prices per 1M tokens.
Implementation
from openai import OpenAI
client = OpenAI(
api_key="ub-gw-...",
base_url="https://api.unoblox.ai/v1"
)
schema = (
"TABLE users (id INT, name VARCHAR, email VARCHAR, created_at DATE)\n"
"TABLE orders (id INT, user_id INT, total DECIMAL, status VARCHAR, created_at DATE)"
)
question = "How many customers signed up last month and how much did they spend?"
prompt = "Schema:\n" + schema + "\n\nQuestion: " + question + "\n\nReturn only a PostgreSQL query, no explanation."
response = client.chat.completions.create(
model="openai/gpt-4-1",
messages=[{"role": "user", "content": prompt}]
)
query = response.choices[0].message.content.strip()
Keeping it safe
Never execute a model's SQL output directly against a production database. Put guardrails around it:
- Read-only by default: connect with a database user that can only
SELECT. - Instruct explicitly: add "generate only SELECT statements; never DELETE, DROP, or UPDATE" to the system prompt.
- Parse before executing: check the generated query only touches expected tables before running it.
- Row and time limits: cap result size and query timeout so a bad join can't lock up your database.
Example questions it handles well
| Question type | Example |
|---|---|
| Aggregation | "Total revenue by month this year" |
| Filtering | "Customers who haven't ordered in 90 days" |
| Joins | "Top 10 products by revenue, with category names" |
| Comparison | "This month's signups vs. last month's" |
Use cases
- Business intelligence dashboards, no-code querying for non-engineers
- Customer support tooling, quick account and data lookups
- Internal analytics without waiting on a data team
- Self-service reporting for sales and finance
Frequently asked questions
Q: How reliable is the generated SQL? A: Simple aggregations and filters are usually correct on the first try; complex multi-table joins benefit from a stronger model (Claude Opus) and should get a human glance before running against production data.
Q: Can I use it across MySQL, PostgreSQL, or Snowflake? A: Yes — state your SQL dialect in the schema description. Most models adapt syntax correctly once told which dialect to target.
Q: What about SQL injection risk? A: The model isn't taking untrusted user input directly into a query string — it's generating the query itself. Still, always run it through a read-only, permission-limited database user, per the guardrails above.
Q: Can I restrict it from ever writing data?
A: Yes — instruct it explicitly to generate only SELECT statements, and enforce that at the database permission level too, not just in the prompt.
Q: How do I handle ambiguous questions like "last month"? A: Give the model today's date and a definition ("last month" = the previous calendar month) in the system prompt, and ask it to state its assumption alongside the query.
Q: Can I ask questions in Hindi and get SQL back? A: Yes — Claude Opus and GPT-4.1 both understand Hindi and regional-language questions and will still return standard SQL.
Get started in rupees → https://unoblox.ai/sign-in
Start building in rupees
Call every major model through one OpenAI-compatible endpoint, billed in ₹ on a GST invoice.