Docs
  • LogicLoop Documentation
  • LogicLoop Quickstart
  • Data Sources
    • Connect your data source
      • Deployment options
    • Supported data sources
      • API data (JSON)
      • AWS CloudWatch
      • BigQuery
      • Databricks
      • Google Analytics
      • Google Sheets
      • MongoDB
      • Microsoft SQL Server
      • MySQL
      • Oracle
      • PostgreSQL
      • Snowflake
      • Combine Results
      • LogicLoop Data Source
  • Queries
    • Write a rule
      • More rule options
      • A/B testing rules
      • Version history
      • Query Snippets
    • Visualizations & dashboards
      • Visualizations
      • Dashboards
  • Actions
    • Set up an action
    • Action destinations
      • Email
      • Slack
      • Webhooks & APIs
      • Microsoft Teams
      • Salesforce
      • Zapier
      • PagerDuty
      • Write to Database
      • Chain Rules
      • Google Sheets
      • Bento
    • Templating
  • Case Management
    • Case Management
      • Ticket Generation
      • Case Triage
      • Custom Fields and Attachments
  • AI
    • AI Query Helper
    • Ask AI
  • Teams & Settings
    • Integrations
      • Slack
      • Google Sheets
    • Invite your teammate
    • Groups & Permissions
  • Changelog
  • FAQs
  • Troubleshooting
  • Templates
    • Templates Home
    • Risk & Fraud Rules
    • AML Transaction Monitoring Rules
    • Logistics & Marketplace Ops
    • Customer Success & Growth
    • Systems Observability
    • Data Quality Monitoring
    • Healthcare
    • HTML Email Templates
      • Annual Review
      • Weekly Performance Table
      • Invoice Recap
  • BETA
    • AI SQL API
    • Approving rules
    • Render Data as JSON
    • Case Analytics
    • Python
  • Security & Legal
    • Security
    • AI Security
    • Terms of use
    • Privacy policy
    • Services description
Powered by GitBook
On this page

Was this helpful?

  1. BETA

AI SQL API

PreviousInvoice RecapNextApproving rules

Last updated 1 year ago

Was this helpful?

Beta features are available to users before official release. Your testing and feedback are an enormous help, please leave any feedback or bug reports you have at support@logicloop.com. Note that beta features are subject to change.

LogicLoop's AI SQL capabilities are available via API if you wish to use AI to generate SQL in your own application. First, if you haven't already created a LogicLoop account .

View the entire collection here and a

Getting started with LogicLoop AI SQL API

Generate SQL based on a natural language request

You can call our SQL generation endpoint in order to generate SQL based on a user request.

Method: POST
URL: https://app.logicloop.com/<YOUR_COMPANY_SLUG>/api/v1/ai/query_generate 
Authorization: Key <YOUR_API_KEY>
Params:
    prompt: A description of the data you're looking for
    model: One of oa-v1, oa-v2, oa-v2-16k, oa-v3 or ant-v1. Defaults to oa-v1.
    data_source_type: One of postgres, mysql, redshift, snowflake, big_query or oracle
    data_schema: A list of dictionaries representing your data schema

Be sure to replace <YOUR_COMPANY_SLUG> which you can find by logging into your dashboard and looking at the URL:

You can find <YOUR API_KEY> by going to Settings > Users > click on your profile > copy the API Key.

You can use either the basic or advanced data schema format below depending on the level of granularity you are looking for.

Data schema format (basic):

[
	{
		"table_name": "table_1",
		"columns": [
			{"name": "col_1"},
			{"name": "col_2"},
			{"name": "col_3"}
		]
	},
	{
		"table_name": "table_2",
		"columns": [
			{"name": "col_1"},
			{"name": "col_2"},
			{"name": "col_3"}
		]
	}
]

Example:

[
	{
		"table_name": "users",
		"columns": [
			{"name": "name"},
			{"name": "id"},
			{"name": "email"}
		]
	},
	{
		"table_name": "orders",
		"columns": [
			{"name": "product"},
			{"name": "id"},
			{"name": "amount"},
			{"name": "status"}
		]
	}
]

Data schema format (advanced):

[
	{
		"table_name": "table_1",
		"columns": [
			{
				"name": "col_1",
				"type": "type_1",
				"description": "description_1",
				"constraint": "primary key"
			},
			{
				"name": "col_2",
				"type": "type_2",
				"description": "description_2"
			},
			{
				"name": "col_3",
				"type": "type_3",
				"description": "description_3"
			}
		]
	},
	{
		"table_name": "table_2",
		"columns": [
			{
				"name": "col_1",
				"type": "type_1",
				"description": "description_1",
				"constraint": "primary key"
			},
			{
				"name": "col_2",
				"type": "type_2",
				"description": "description_2",
				"constraint": "foreign key references table_1(col_1)"
			},
			{
				"name": "col_3",
				"type": "type_3",
				"description": "description_3"
			}
		]
	}
]

Example:

[
	{
		"table_name": "users",
		"columns": [
			{
				"name": "name",
				"type": "string",
				"description": "The users given name"
			},
			{
				"name": "id",
				"type": "int",
				"description": "The users unique identifier",
				"constraint": "primary key"
			},
			{
				"name": "email",
				"type": "string",
				"description": "The users contact email address"
			}
		]
	},
	{
		"table_name": "orders",
		"columns": [
			{
				"name": "id",
				"type": "int",
				"description": "The orders unique identifier",
				"constraint": "primary key"
			},
			{
				"name": "user_id",
				"type": "int",
				"description": "The id of the user who this order belongs to",
				"constraint": "foreign key references users(id)"
			},
			{
				"name": "amount",
				"type": "int",
				"description": "The total price of the order in USD"
			},
			{
				"name": "status",
				"type": "enum(canceled, pending, completed)",
				"description": "The shipping status of this order"
			}
		]
	}
]

Sample CURL request

curl -X POST https://app.logicloop.com//api/v1/ai/query_generate -H "Authorization: Key <YOUR_API_KEY>" -d '{"prompt":"Help me find invalid emails","data_source_type":"postgres", "data_schema": [{"table_name": "users", "columns": [{"name": "name"}, {"name": "id"}, {"name": "email"}]}]}' 

Response

{"query_response":"SELECT name, id, email\nFROM users\nWHERE email NOT LIKE '%@%.%';\n"}

you can do so here
Getting started with LogicLoop AI SQL API Demo
Run in Postman