{"id":32617624,"url":"https://github.com/boundaryml/baml-db-query","last_synced_at":"2026-06-29T20:31:10.443Z","repository":{"id":276268920,"uuid":"928524676","full_name":"BoundaryML/baml-db-query","owner":"BoundaryML","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-07T07:59:46.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-07T08:28:10.462Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BoundaryML.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-06T19:15:44.000Z","updated_at":"2025-02-07T07:59:50.000Z","dependencies_parsed_at":"2025-02-07T08:39:24.955Z","dependency_job_id":null,"html_url":"https://github.com/BoundaryML/baml-db-query","commit_stats":null,"previous_names":["boundaryml/baml-db-query"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BoundaryML/baml-db-query","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml-db-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml-db-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml-db-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml-db-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BoundaryML","download_url":"https://codeload.github.com/BoundaryML/baml-db-query/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoundaryML%2Fbaml-db-query/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34942665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-30T17:02:05.531Z","updated_at":"2026-06-29T20:31:10.429Z","avatar_url":"https://github.com/BoundaryML.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BAML Demo\n\nThis repository contains demo code showcasing the BAML library. The demo demonstrates how to:\n\n- Select relevant tables from a SQL schema based on a user query.\n- Generate a SQL query based on the selected tables and columns.\n- Use chain-of-thought prompts to help the model decide which tables and columns are relevant.\n\nVideo demo: [https://youtu.be/iBqTB_7Avt0](https://youtu.be/iBqTB_7Avt0)\n\n## Overview\n\nThere are two main components in this demo:\n\n1. **`app/main.py`**  \n   This Python script performs the following:\n   - Prompts the user for a SQL-related question (with an option to use a default).\n   - Uses the BAML library to select relevant tables and columns based on the given question.\n   - Filters the SQL schema to include only the relevant parts.\n   - Requests the model to generate an SQL query.\n   - Displays the selected tables, columns, and the generated SQL query with formatted colored output.\n\n2. **`app/baml_src/extract-tables.baml`**  \n   This BAML file defines:\n   - A schema for table metadata.\n   - A function to select relevant tables from the provided schema based on the user's question.\n   - Testing blocks to verify the selection process for different queries.\n\n## Prerequisites\n\n- Python 3.7 or later.\n- The [BAML client library](#) installed and properly configured.\n- Dependencies such as `colorama`. You can install them via pip manually or through a `requirements.txt` if available.\n\n## Setup and Installation\n\n1. **Clone the Repository**\n\n   ```bash\n   git clone https://github.com/BoundaryML/baml-db-query.git\n   cd baml-db-query\n   ```\n\n2. **Install Dependencies**\n\n    \u003e consider using a virtual environment\n    \u003e\n    \u003e `python -m venv venv`\n    \u003e\n    \u003e `source venv/bin/activate`\n\n\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n3. **Set Up the BAML**\n\n    Convert from `*.baml` to `*.py` using the following command:\n\n    ```bash\n    baml-cli generate\n    ```\n\n    You should now see a directory called `baml_client`.\n\n    \u003e Alternatively, you can save any `.baml` file while you have the BAML VSCode/Cursor extension and that will run the command for you.\n\n4. **Set Up the Environment**\n\n   - Set the `OPENAI_API_KEY` environment variable to your OpenAI API key.\n\n   ```bash\n   export OPENAI_API_KEY=\u003cyour-api-key\u003e\n   ```\n\n## Running the Demo\n\nRun the demo using the following command:\n\n```bash\nBAML_LOG=warn python app/main.py\n```\n\n## Example Output\n\n### Default question\n\n```bash\nBAML_LOG=warn python app/main.py\nEnter your question (default: 'What are the top 10 most popular products in the database?'): What are the top 10 most popular products in the database?\n--------------------------------------------------\nQuestion: What are the top 10 most popular products in the database?\n--------------------------------------------------\nSelecting Relevant Tables...\nTable Selected: cart\n  - product_id\n  - quantity\nTable Selected: products\n  - id\n  - name\n--------------------------------------------------\nGenerating SQL Query...\nQuery:\nSELECT p.name, SUM(c.quantity) AS total_quantity FROM products p JOIN cart c ON p.id = c.product_id GROUP BY p.id, p.name ORDER BY total_quantity DESC LIMIT 10;\n--------------------------------------------------\n```\n\n### Unrelated question\n\n```bash\nBAML_LOG=warn python app/main.py\nEnter your question (default: 'What are the top 10 most popular products in the database?'): how old is obama\n--------------------------------------------------\nQuestion: how old is obama\n--------------------------------------------------\nSelecting Relevant Tables...\nSorry, I can't help with that question.\nReason: The question is not relevant to the tables as it pertains to the age of a public figure, Barack Obama, which is not related to the database schema provided.\n```\n\nFeel free to explore and modify the demo to better understand and showcase the capabilities of BAML.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboundaryml%2Fbaml-db-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboundaryml%2Fbaml-db-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboundaryml%2Fbaml-db-query/lists"}