Go SDK Demo – using TSZ client from source repository
This example shows how to consume the TSZ Go SDK from the source repository repository:
import tszclient "source.example/thyris/safe-zone/pkg/tszclient-go"
It demonstrates both:
- Calling the core
/detectAPI for PII detection and guardrails - Calling the chat-completions-compatible LLM gateway
/v1/chat/completions
The example lives alongside the TSZ source code in this repo, but it is
structured as if it were an external project with its own go.mod.
Files
-
main.go- Creates a TSZ client with
BaseURL = http://localhost:8080 - Sends a
/detectrequest usingDetectTextand prints the redacted text - Sends a
/v1/chat/completionsrequest usingChatCompletionsand prints the LLM reply
- Creates a TSZ client with
-
go.mod- Declares a separate module name (
example.com/tsz-go-sdk-external-demo) - Depends on
source.example/thyris/safe-zone - Uses a
replacedirective so that inside this repository the SDK is resolved from the local checkout instead of fetching it from source repository
- Declares a separate module name (
In your own project, you can drop the replace line and use a normal
go get with a tagged version or commit.
How to run this example (inside this repo)
From the repository root:
cd examples/go-sdk-demo
# Optional, but recommended to ensure dependencies are in place
go mod tidy
# Run the demo
go run .
You should see log output similar to:
/detectresponse:- Redacted text (e.g. email addresses masked)
- A breakdown map with detection counts
/v1/chat/completionsresponse:- A short reply from the LLM, returned via the TSZ gateway
Prerequisites:
- TSZ is running locally and accessible at
http://localhost:8080(for example viadocker compose -f deployment/docker/docker-compose.yml upas described in the main README/QUICK_START). - The upstream LLM configured in
.env/AI_MODEL_URL/AI_MODELis reachable and supports the chosen model (e.g.llama3.1:8b).
Using this pattern in your own project
In a separate project, you can follow the same pattern without the replace:
mkdir my-tsz-demo
cd my-tsz-demo
go mod init my-tsz-demo
go get source.example/thyris/safe-zone@<version>
Then in your main.go:
import tszclient "source.example/thyris/safe-zone/pkg/tszclient-go"
You can copy/paste the logic from main.go in this directory and adjust:
BaseURLto point at your TSZ deployment- The model name to match your configured upstream LLM
- Guardrail headers / RIDs according to your needs
For more details on the TSZ Go client, see:
pkg/tszclient-go/README.mdin this repository