Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 113 additions & 7 deletions .github/workflows/dotnet-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,132 @@ name: dotnet-client
on:
push:
branches: [main]
paths: ["clients/dotnet/**", ".github/workflows/dotnet-client.yml"]
paths:
- "clients/dotnet/**"
- "examples/dotnet/**"
- "scripts/build-engine.py"
- "scripts/engine_main.py"
- ".github/workflows/dotnet-client.yml"
pull_request:
paths: ["clients/dotnet/**", ".github/workflows/dotnet-client.yml"]
paths:
- "clients/dotnet/**"
- "examples/dotnet/**"
- "scripts/build-engine.py"
- "scripts/engine_main.py"
- ".github/workflows/dotnet-client.yml"

permissions:
contents: read

jobs:
# Unit tests and the whole conformance corpus, in remote mode and in local mode (the engine over stdio), on the
# three operating systems. SQLGUARD_REQUIRE_CONFORMANCE makes a missing engine a failure instead of a skip.
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: clients/dotnet
name: test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
SQLGUARD_REQUIRE_CONFORMANCE: "1"
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
with:
python-version: "3.12"
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
- name: Python environment of the engine and the server (warms uv so the tests do not time out on it)
run: uv sync --locked --extra serve
- run: dotnet build -c Release
working-directory: clients/dotnet
- run: dotnet test -c Release --no-build
- run: dotnet pack src/SqlGuardLlm -c Release -o out
working-directory: clients/dotnet

# The package as a user gets it: the engine of this platform is built, staged, packed, and then a consumer project
# restores the PACKED package and runs with `dotnet run`, `dotnet publish -r <rid>` (framework-dependent, then
# self-contained single-file, then trimmed, then Native AOT, each with trimming and AOT warnings as errors), and, on
# Linux, in a container image with no .NET installed. The SHA-256 check is exercised by tampering with a file.
package:
name: package (${{ matrix.rid }})
runs-on: ${{ matrix.os }}
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-24.04, rid: linux-x64, platform: linux-x64 }
- { os: macos-15, rid: osx-arm64, platform: macos-arm64 }
- { os: windows-2022, rid: win-x64, platform: windows-x64 }
defaults:
run:
shell: bash
env:
WARNINGS: "IL2026;IL2046;IL2057;IL2060;IL2062;IL2067;IL2070;IL2072;IL2075;IL2087;IL2091;IL3050;IL3051;IL3053"
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
with:
python-version: "3.12"
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
- name: Native AOT toolchain (Linux)
if: startsWith(matrix.rid, 'linux')
run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev
- name: Build the engine of this platform (PyInstaller one-dir, as in engine-binaries.yml)
run: |
uv run --isolated --no-dev --with "pyinstaller==6.22.3" python scripts/build-engine.py --out dist-engine
mkdir -p "engines/${{ matrix.platform }}"
cp -R "dist-engine/sqlguardllm-engine-${{ matrix.platform }}" "engines/${{ matrix.platform }}/"
- name: Stage the engine and pack the four packages
run: |
set -e
V=$(sed -nE 's#.*<Version>(.*)</Version>.*#\1#p' clients/dotnet/Directory.Build.props)
python3 clients/dotnet/build/stage-engines.py --engines engines --platform "${{ matrix.platform }}"
for p in SqlGuardLlm SqlGuardLlm.Extensions SqlGuardLlm.EntityFrameworkCore SqlGuardLlm.SemanticKernel; do
dotnet pack "clients/dotnet/src/$p" -c Release -o clients/dotnet/out
done
ls -l clients/dotnet/out
python3 clients/dotnet/build/stage-engines.py --check-nupkg clients/dotnet/out/SqlGuardLlm.$V.nupkg --allow-partial
# the symbols package exists and SourceLink points at this commit
ls clients/dotnet/out/SqlGuardLlm.$V.snupkg
unzip -p clients/dotnet/out/SqlGuardLlm.$V.nupkg SqlGuardLlm.nuspec | grep -q "commit=\"$GITHUB_SHA\""
- name: dotnet run, framework-dependent publish, self-contained single-file publish
run: |
set -e
V=$(sed -nE 's#.*<Version>(.*)</Version>.*#\1#p' clients/dotnet/Directory.Build.props)
echo "SQLGUARD_PKG_VERSION=$V" >> "$GITHUB_ENV"
S=clients/dotnet/smoke
dotnet run --project $S -c Release -p:SqlGuardLlmVersion=$V
dotnet publish $S -c Release -r ${{ matrix.rid }} --no-self-contained -p:SqlGuardLlmVersion=$V -o out-fdd
./out-fdd/Smoke
dotnet publish $S -c Release -r ${{ matrix.rid }} --self-contained -p:PublishSingleFile=true -p:SqlGuardLlmVersion=$V -o out-single
./out-single/Smoke
- name: A tampered engine file refuses to start
run: |
set -e
echo x >> out-single/sqlguardllm-engine/_internal/base_library.zip
if ./out-single/Smoke > tamper.txt 2>&1; then echo "tampered engine started"; exit 1; fi
cat tamper.txt; grep -q "SHA-256 mismatch" tamper.txt
- name: Trimmed and Native AOT publish, warnings as errors
run: |
set -e
S=clients/dotnet/smoke; V=$SQLGUARD_PKG_VERSION
dotnet publish $S -c Release -r ${{ matrix.rid }} --self-contained -p:PublishTrimmed=true -p:TrimmerSingleWarn=false "-p:WarningsAsErrors=${WARNINGS//;/%3B}" -p:SqlGuardLlmVersion=$V -o out-trim
./out-trim/Smoke
dotnet publish $S -c Release -r ${{ matrix.rid }} -p:PublishAot=true "-p:WarningsAsErrors=${WARNINGS//;/%3B}" -p:SqlGuardLlmVersion=$V -o out-aot
./out-aot/Smoke
- name: Linux container image (no .NET inside)
if: startsWith(matrix.rid, 'linux')
run: |
set -e
dotnet publish clients/dotnet/smoke -c Release -r ${{ matrix.rid }} --self-contained -p:PublishSingleFile=true -p:SqlGuardLlmVersion=$SQLGUARD_PKG_VERSION -o out-container
docker build -f clients/dotnet/smoke/Dockerfile -t sqlguard-smoke out-container
docker run --rm sqlguard-smoke
44 changes: 44 additions & 0 deletions .github/workflows/recipes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,47 @@ jobs:
--with "llama-index-core>=0.14,<0.15"
--with "vanna>=2.0,<2.1"
python -m pytest tests/test_examples.py -W ignore::DeprecationWarning

# The Node.js recipes (examples/node: LangChain.js, Vercel AI SDK, pg, mysql2, Prisma), with the real engine in local
# mode, executing on SQLite (node:sqlite) and on a PostgreSQL 16 service container.
node-recipes:
name: Node.js recipes
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres # throwaway container of this job, not a secret
ports: ["5432:5432"]
options: >-
--health-cmd "pg_isready -U postgres" --health-interval 5s --health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
with:
python-version: "3.12"
enable-cache: true
- uses: actions/setup-node@v4
with:
node-version: "24"
- name: Engine from this checkout
run: uv sync --locked
- name: Build the Node client the recipes import
working-directory: clients/node
run: |
npm ci
npm run build
- name: Recipes (a missing framework fails instead of skipping)
working-directory: examples/node
env:
SQLGUARDLLM_RECIPES: "1"
SQLGUARD_ENGINE_CMD: uv run --project ${{ github.workspace }} sqlguardllm engine --stdio
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
run: |
npm install
npm test
- name: The runnable demo (npm start) with the real engine, on SQLite
working-directory: examples/node
env:
SQLGUARD_ENGINE_CMD: uv run --project ${{ github.workspace }} sqlguardllm engine --stdio
run: node run.mjs
56 changes: 46 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ jobs:
if [ "$npm_version" != "$node_version" ]; then
echo "clients/node/package.json has $node_version, expected $npm_version"; exit 1
fi
dotnet_version=$(sed -nE 's#.*<Version>(.*)</Version>.*#\1#p' clients/dotnet/src/SqlGuardLlm/SqlGuardLlm.csproj)
# The four .NET packages share one version, in clients/dotnet/Directory.Build.props.
dotnet_version=$(sed -nE 's#.*<Version>(.*)</Version>.*#\1#p' clients/dotnet/Directory.Build.props)
if [ "$npm_version" != "$dotnet_version" ]; then
echo "SqlGuardLlm.csproj has $dotnet_version, expected $npm_version"; exit 1
echo "clients/dotnet/Directory.Build.props has $dotnet_version, expected $npm_version"; exit 1
fi
if grep -rq '<Version>' clients/dotnet/src --include=*.csproj; then
echo "a .csproj under clients/dotnet/src sets its own <Version>; it must come from Directory.Build.props"; exit 1
fi
# Before 1.0 every release is a prerelease, so `latest` (what `npm install sqlguardllm`
# and the npm page use) follows the newest one. From 1.0 on, prereleases get their own tag.
Expand Down Expand Up @@ -176,38 +180,70 @@ jobs:
TAG: ${{ needs.build.outputs.npm_tag }}
run: node npm/publish.mjs --out npm/dist --tag "$TAG"

# The four packages (SqlGuardLlm with the five engines as runtimes/{rid}/native assets, then the three integration
# packages that depend on it), same version, symbols (.snupkg) with them. The engines are the attested archives of
# this same run, verified before anything is unpacked. Before the push, the packed package is restored by a consumer
# project and the engine of this runner is started from it (SHA-256 check included).
nuget:
name: Publish the .NET client to NuGet
needs: [build, engines]
name: Publish the .NET packages to NuGet
needs: [build, engines, attest]
runs-on: ubuntu-latest
environment:
name: nuget
url: https://www.nuget.org/packages/SqlGuardLlm
permissions:
contents: read
id-token: write
defaults:
run:
working-directory: clients/dotnet
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
- uses: actions/download-artifact@v4
with:
name: engine-release
path: engine-release/
- name: Verify the engine archives (attestation, then checksums), unpack and stage them
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.build.outputs.version }}
run: |
set -e
for f in engine-release/*; do
gh attestation verify "$f" --repo "$GITHUB_REPOSITORY"
done
python3 scripts/fetch-engine.py "$VERSION" --base-url engine-release --no-attestation --out engines
python3 clients/dotnet/build/stage-engines.py --engines engines
- run: dotnet build -c Release
working-directory: clients/dotnet
- run: dotnet test -c Release --no-build
- run: dotnet pack src/SqlGuardLlm -c Release --no-build -o out
working-directory: clients/dotnet
- name: Pack (deterministic, SourceLink, symbols) and check size and contents
env:
NPM_VERSION: ${{ needs.build.outputs.npm_version }}
run: |
set -e
for p in SqlGuardLlm SqlGuardLlm.Extensions SqlGuardLlm.EntityFrameworkCore SqlGuardLlm.SemanticKernel; do
dotnet pack "clients/dotnet/src/$p" -c Release --no-build -o clients/dotnet/out
test -f "clients/dotnet/out/$p.$NPM_VERSION.nupkg"
test -f "clients/dotnet/out/$p.$NPM_VERSION.snupkg"
done
python3 clients/dotnet/build/stage-engines.py --check-nupkg "clients/dotnet/out/SqlGuardLlm.$NPM_VERSION.nupkg"
- name: Consumer check, restoring the packed package and starting its engine
env:
NPM_VERSION: ${{ needs.build.outputs.npm_version }}
run: dotnet run --project clients/dotnet/smoke -c Release -p:SqlGuardLlmVersion="$NPM_VERSION"
# Exchanges the job's OIDC token for an API key that lives one hour.
- name: NuGet login (Trusted Publishing)
id: login
uses: NuGet/login@v1
with:
user: ${{ vars.NUGET_USER }}
- name: Push (the .snupkg symbols go with it)
- name: Push the four packages (each .snupkg goes with its .nupkg)
run: >-
dotnet nuget push "out/*.nupkg"
dotnet nuget push "clients/dotnet/out/*.nupkg"
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}"
--source https://api.nuget.org/v3/index.json
--skip-duplicate
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ __pycache__/
htmlcov/
dist/
build/
!clients/dotnet/build/
*.egg-info/
site/
.env
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ All notable changes to sqlguardllm are documented here. The format follows [Keep

## [Unreleased]

### Fixed
- Node.js: a program that ends with a top-level `await guard.close()` on a local-mode guard exited with an unsettled await (code 13), because the engine process is unref'd and nothing kept the event loop alive while `close()` waited for it to exit. `close()` now keeps the loop alive until the engine exits (at most 2 s).
- .NET: `dotnet pack` failed with NU5123 once the engines were staged, and a RID-specific publish (`dotnet publish -r <rid>`, self-contained, single-file, container images) failed with NETSDK1152 or lost the engine folder, because the SDK flattens native assets. The package now ships `build/SqlGuardLlm.targets`, which keeps the `sqlguardllm-engine/` folder intact next to the app (#76).
- The NuGet release job pushed `SqlGuardLlm` without the engines (nothing staged them) and did not push the integration packages (#76, #79).

### Added
- .NET release and CI (#76, #77, #79): `clients/dotnet/build/stage-engines.py` (it was documented but missing) stages the attested engine archives with an `engine.sha256` manifest and fails when the package passes 150 MB; `clients/dotnet/Directory.Build.props` holds one version for the four packages, with SourceLink, deterministic builds and `.snupkg` symbols for all of them, and `release.yml` checks it against the engine release, verifies the engine archives, packs and pushes `SqlGuardLlm`, `SqlGuardLlm.Extensions`, `SqlGuardLlm.EntityFrameworkCore` and `SqlGuardLlm.SemanticKernel`, after a consumer project restored the packed package and started its engine. `dotnet-client.yml` now runs the unit tests and the whole conformance corpus in local mode on Linux, macOS and Windows (a missing engine fails instead of skipping), and a `package` job builds the engine of each platform, packs, and runs `clients/dotnet/smoke` with `dotnet run`, `dotnet publish -r <rid>` (framework-dependent, self-contained single-file, trimmed and Native AOT with trimming and AOT warnings as errors), a tampered-engine check and, on Linux, a container image.
- Node.js recipes (#74): the `Recipes` workflow has a `node-recipes` job that runs `examples/node` with the real engine in local mode on SQLite and on a PostgreSQL 16 service container. `examples/node/run.mjs` and the tests accept `SQLGUARD_ENGINE_CMD`.
- Node.js and .NET guides, quickstart pointers, package chooser and READMEs (English and Spanish) now describe the embedded engine (`SqlGuard.local`, `SqlGuard.CreateLocalAsync`) as the default path and the server as the remote mode.
- **.NET integrations (#78).** `SqlGuardLlm.Extensions` (`services.AddSqlGuard(...)` with options bound from configuration, ADO.NET and Dapper helpers, a Microsoft.Extensions.AI `GuardedSqlFunction`), `SqlGuardLlm.EntityFrameworkCore` (a `DbCommandInterceptor` that enforces raw SQL) and `SqlGuardLlm.SemanticKernel` (a function invocation filter), plus runnable examples in `examples/dotnet/`.
- Node.js recipes (#74) in `examples/node/`: a guarded `sql_db_query` tool for LangChain.js, a guarded `tool()` for the Vercel AI SDK and runners for `pg`, `mysql2` and Prisma `$queryRawUnsafe`, all through `enforce()`, with SQLite and (with `DATABASE_URL`) PostgreSQL tests. See `docs/RECIPES.md`.

## [0.5.0a5] - 2026-11-27

First release whose npm package carries the embedded engine: `npm install sqlguardllm` can run it with no Python and no server (`SqlGuard.local`). The .NET package ships the engine as runtime assets with a local mode.
Expand Down
Loading
Loading