# HeimdaLLM
Pronounced `[ˈhaɪm.dɔl.əm]` or _HEIM-dall-EM_
HeimdaLLM is a robust static analysis framework for validating that LLM-generated
structured output is safe. It currently supports SQL.
In simple terms, it helps makes sure that AI won't wreck your systems.
[![Heimdall](https://raw.githubusercontent.com/amoffat/HeimdaLLM/main/docs/source/images/heimdall.png)](https://heimdallm.ai)
[![Build status](https://github.com/amoffat/HeimdaLLM/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/amoffat/HeimdaLLM/actions)
[![Docs](https://img.shields.io/badge/Documentation-purple.svg)](https://docs.heimdallm.ai)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/amoffat)](https://github.com/sponsors/amoffat)
[![PyPI](https://img.shields.io/pypi/v/heimdallm)](https://pypi.org/project/heimdallm/)
[![License: Commercial](https://img.shields.io/badge/License-Commercial-blue.svg)](https://forms.gle/frEPeeJx81Cmwva78)
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![Coverage Status](https://coveralls.io/repos/github/amoffat/HeimdaLLM/badge.svg?branch=dev)](https://coveralls.io/github/amoffat/HeimdaLLM?branch=dev)
Consider the following natural-language database query:
```
how much have i spent renting movies, broken down by month?
```
From this query (and a little bit of context), an LLM can produce the following SQL
query:
```sql
SELECT
strftime('%Y-%m', payment.payment_date) AS month,
SUM(payment.amount) AS total_amount
FROM payment
JOIN rental ON payment.rental_id=rental.rental_id
JOIN customer ON payment.customer_id=customer.customer_id
WHERE customer.customer_id=:customer_id
GROUP BY month
LIMIT 10;
```
But how can you ensure the LLM-generated query is safe and that it only accesses
authorized data?
HeimdaLLM performs static analysis on the generated SQL to ensure that only certain
columns, tables, and functions are used. It also automatically edits the query to add a
`LIMIT` and to remove forbidden columns. Lastly, it ensures that there is a column
constraint that would restrict the results to only the user's data.
It does all of this locally, without AI, using good ol' fashioned grammars and parsers:
```
✅ Ensuring SELECT statement...
✅ Resolving column and table aliases...
✅ Allowlisting selectable columns...
✅ Removing 2 forbidden columns...
✅ Ensuring correct row LIMIT exists...
✅ Lowering row LIMIT to 10...
✅ Checking JOINed tables and conditions...
✅ Checking required WHERE conditions...
✅ Ensuring query is constrained to requester's identity...
✅ Allowlisting SQL functions...
✅ strftime
✅ SUM
```
The validated query can then be executed:
| month | total_amount |
| ------- | ------------ |
| 2005-05 | 4.99 |
| 2005-06 | 22.95 |
| 2005-07 | 100.78 |
| 2005-08 | 87.82 |
Want to get started quickly? Go
[here](https://docs.heimdallm.ai/en/latest/quickstart/index.html).
# 🥽 Safety
I am in the process of organizing an independent security audit of HeimdaLLM. Until this
audit is complete, I do not recommend using HeimdaLLM against any production system
without a careful risk assessment. These audits are self-funded, so if you will get
value from the confidence that they bring, consider [sponsoring
me](https://github.com/sponsors/amoffat) or [inquire about interest in a commercial
license](https://forms.gle/frEPeeJx81Cmwva78).
To understand some of the potential vulnerabilities, take a look at the [attack
surface](https://docs.heimdallm.ai/en/latest/attack-surface.html) to see the risks and
the mitigations.
# 📚 Database support
- Sqlite
- MySQL
- Postgres
There is active development for the other top relational SQL databases. To help me
prioritize, please vote on which database you would like to see supported:
[![Static Badge](https://img.shields.io/badge/Vote!-here-limegreen)](https://github.com/amoffat/HeimdaLLM/discussions/2)
# 📜 License
HeimdaLLM is dual-licensed for open-source or for commercial use.
## 🤝 Open-source license
The open-source license is [AGPLv3](https://www.gnu.org/licenses/agpl-3.0.en.html),
which permits free usage, modification, and distribution, and is appropriate for
individual or open-source usage. For commercial usage, AGPLv3 has key obligations that
your organization may want to avoid:
- **Source Code Disclosure:** Any changes you make and use over a network must be made
publicly available, potentially revealing your proprietary modifications.
- **Copyleft Clause:** If HeimdaLLM is integrated into your application, the whole
application may need to adhere to AGPLv3 terms, including code disclosure of your
application.
- **Service Providers:** If you use HeimdaLLM to provide services, your clients also
need to abide by AGPLv3, complicating contracts.
## 📈 Commercial license
The commercial license eliminates the above restrictions, providing flexibility and
protection for your business operations. This commercial license is recommended for
commercial use. Please inquire about a commerical license here:
[![License Inquiry](https://img.shields.io/badge/License%20inquiry-blue)](https://forms.gle/frEPeeJx81Cmwva78)
Raw data
{
"_id": null,
"home_page": "https://github.com/amoffat/HeimdaLLM",
"name": "heimdallm",
"maintainer": "Andrew Moffat",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "arwmoffat@gmail.com",
"keywords": "sql,llm,ai",
"author": "Andrew Moffat",
"author_email": "arwmoffat@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a9/1a/32d5e0561342262a164e1a310fb9389a11af47b73b8b3fb1eee485cfd4f2/heimdallm-1.0.3.tar.gz",
"platform": null,
"description": "# HeimdaLLM\n\nPronounced `[\u02c8ha\u026am.d\u0254l.\u0259m]` or _HEIM-dall-EM_\n\nHeimdaLLM is a robust static analysis framework for validating that LLM-generated\nstructured output is safe. It currently supports SQL.\n\nIn simple terms, it helps makes sure that AI won't wreck your systems.\n\n[![Heimdall](https://raw.githubusercontent.com/amoffat/HeimdaLLM/main/docs/source/images/heimdall.png)](https://heimdallm.ai)\n[![Build status](https://github.com/amoffat/HeimdaLLM/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/amoffat/HeimdaLLM/actions)\n[![Docs](https://img.shields.io/badge/Documentation-purple.svg)](https://docs.heimdallm.ai)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/amoffat)](https://github.com/sponsors/amoffat)\n[![PyPI](https://img.shields.io/pypi/v/heimdallm)](https://pypi.org/project/heimdallm/)\n[![License: Commercial](https://img.shields.io/badge/License-Commercial-blue.svg)](https://forms.gle/frEPeeJx81Cmwva78)\n[![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)\n[![Coverage Status](https://coveralls.io/repos/github/amoffat/HeimdaLLM/badge.svg?branch=dev)](https://coveralls.io/github/amoffat/HeimdaLLM?branch=dev)\n\nConsider the following natural-language database query:\n\n```\nhow much have i spent renting movies, broken down by month?\n```\n\nFrom this query (and a little bit of context), an LLM can produce the following SQL\nquery:\n\n```sql\nSELECT\n strftime('%Y-%m', payment.payment_date) AS month,\n SUM(payment.amount) AS total_amount\nFROM payment\nJOIN rental ON payment.rental_id=rental.rental_id\nJOIN customer ON payment.customer_id=customer.customer_id\nWHERE customer.customer_id=:customer_id\nGROUP BY month\nLIMIT 10;\n```\n\nBut how can you ensure the LLM-generated query is safe and that it only accesses\nauthorized data?\n\nHeimdaLLM performs static analysis on the generated SQL to ensure that only certain\ncolumns, tables, and functions are used. It also automatically edits the query to add a\n`LIMIT` and to remove forbidden columns. Lastly, it ensures that there is a column\nconstraint that would restrict the results to only the user's data.\n\nIt does all of this locally, without AI, using good ol' fashioned grammars and parsers:\n\n```\n\u2705 Ensuring SELECT statement...\n\u2705 Resolving column and table aliases...\n\u2705 Allowlisting selectable columns...\n \u2705 Removing 2 forbidden columns...\n\u2705 Ensuring correct row LIMIT exists...\n \u2705 Lowering row LIMIT to 10...\n\u2705 Checking JOINed tables and conditions...\n\u2705 Checking required WHERE conditions...\n\u2705 Ensuring query is constrained to requester's identity...\n\u2705 Allowlisting SQL functions...\n \u2705 strftime\n \u2705 SUM\n```\n\nThe validated query can then be executed:\n\n| month | total_amount |\n| ------- | ------------ |\n| 2005-05 | 4.99 |\n| 2005-06 | 22.95 |\n| 2005-07 | 100.78 |\n| 2005-08 | 87.82 |\n\nWant to get started quickly? Go\n[here](https://docs.heimdallm.ai/en/latest/quickstart/index.html).\n\n# \ud83e\udd7d Safety\n\nI am in the process of organizing an independent security audit of HeimdaLLM. Until this\naudit is complete, I do not recommend using HeimdaLLM against any production system\nwithout a careful risk assessment. These audits are self-funded, so if you will get\nvalue from the confidence that they bring, consider [sponsoring\nme](https://github.com/sponsors/amoffat) or [inquire about interest in a commercial\nlicense](https://forms.gle/frEPeeJx81Cmwva78).\n\nTo understand some of the potential vulnerabilities, take a look at the [attack\nsurface](https://docs.heimdallm.ai/en/latest/attack-surface.html) to see the risks and\nthe mitigations.\n\n# \ud83d\udcda Database support\n\n- Sqlite\n- MySQL\n- Postgres\n\nThere is active development for the other top relational SQL databases. To help me\nprioritize, please vote on which database you would like to see supported:\n\n[![Static Badge](https://img.shields.io/badge/Vote!-here-limegreen)](https://github.com/amoffat/HeimdaLLM/discussions/2)\n\n# \ud83d\udcdc License\n\nHeimdaLLM is dual-licensed for open-source or for commercial use.\n\n## \ud83e\udd1d Open-source license\n\nThe open-source license is [AGPLv3](https://www.gnu.org/licenses/agpl-3.0.en.html),\nwhich permits free usage, modification, and distribution, and is appropriate for\nindividual or open-source usage. For commercial usage, AGPLv3 has key obligations that\nyour organization may want to avoid:\n\n- **Source Code Disclosure:** Any changes you make and use over a network must be made\n publicly available, potentially revealing your proprietary modifications.\n\n- **Copyleft Clause:** If HeimdaLLM is integrated into your application, the whole\n application may need to adhere to AGPLv3 terms, including code disclosure of your\n application.\n\n- **Service Providers:** If you use HeimdaLLM to provide services, your clients also\n need to abide by AGPLv3, complicating contracts.\n\n## \ud83d\udcc8 Commercial license\n\nThe commercial license eliminates the above restrictions, providing flexibility and\nprotection for your business operations. This commercial license is recommended for\ncommercial use. Please inquire about a commerical license here:\n\n[![License Inquiry](https://img.shields.io/badge/License%20inquiry-blue)](https://forms.gle/frEPeeJx81Cmwva78)\n\n",
"bugtrack_url": null,
"license": "AGPL-3.0",
"summary": "Construct trusted SQL queries from untrusted input",
"version": "1.0.3",
"project_urls": {
"Documentation": "https://heimdallm.readthedocs.io/en/latest/",
"Homepage": "https://github.com/amoffat/HeimdaLLM",
"Repository": "https://github.com/amoffat/HeimdaLLM"
},
"split_keywords": [
"sql",
"llm",
"ai"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "272df8c5ffa84b620adaab622babbd5151a2c14188acf87f915067bfca0c73b5",
"md5": "6644d74c732e31c157221866b4330dba",
"sha256": "36690b868fb8775b565c9842ad1ba7b124e568766298a61c2e4ddceddc0eebad"
},
"downloads": -1,
"filename": "heimdallm-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6644d74c732e31c157221866b4330dba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 92579,
"upload_time": "2024-02-03T08:47:41",
"upload_time_iso_8601": "2024-02-03T08:47:41.746047Z",
"url": "https://files.pythonhosted.org/packages/27/2d/f8c5ffa84b620adaab622babbd5151a2c14188acf87f915067bfca0c73b5/heimdallm-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a91a32d5e0561342262a164e1a310fb9389a11af47b73b8b3fb1eee485cfd4f2",
"md5": "ef4c700014577a59121107987243e96d",
"sha256": "38da659e9da9339458378be1322f81fc3c1b1a76249ae0a0ec9f7ffb81ecdc63"
},
"downloads": -1,
"filename": "heimdallm-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "ef4c700014577a59121107987243e96d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 59987,
"upload_time": "2024-02-03T08:47:43",
"upload_time_iso_8601": "2024-02-03T08:47:43.783626Z",
"url": "https://files.pythonhosted.org/packages/a9/1a/32d5e0561342262a164e1a310fb9389a11af47b73b8b3fb1eee485cfd4f2/heimdallm-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-03 08:47:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "amoffat",
"github_project": "HeimdaLLM",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "heimdallm"
}