Safeguard AI SDKs
Queries
Ask Safeguard AI a question from TypeScript, Python or Go and read the whole answer, with conversation, product and model options.
Queries
query sends one prompt and waits for the whole answer. Use streaming when you want the answer as it is produced.
| Option | Meaning |
|---|---|
| Conversation id | Continue this conversation. Left out, a new conversation is created and its id is in the result. |
| Product id | One of the products the key's owner can use (see context()). Left out, the client's product, else the owner's active product. |
| Model | A Safeguard model tier. Left out, the service default (griffin-2o). |
The result holds conversationId, queryId, answer and model.
TypeScript
const result = await client.query("In two sentences, what is an SBOM?", {
conversationId: undefined, // or an id from a previous result
productId: undefined, // or an id from client.context()
model: undefined, // or a model tier
});
console.log(result.conversationId, result.queryId, result.model);
console.log(result.answer);Every call also takes an AbortSignal as signal.
Python
result = client.query(
"In two sentences, what is an SBOM?",
conversation_id=None, # or an id from a previous result
product_id=None, # or an id from client.context()
model=None, # or a model tier
)
print(result.conversation_id, result.query_id, result.model)
print(result.answer)Go
res, err := client.Query(ctx, "In two sentences, what is an SBOM?", &safeguard.QueryOptions{
ConversationID: "", // or an id from a previous result
ProductID: "", // or an id from client.Context
Model: "", // or a model tier
})
if err != nil {
log.Fatal(err)
}
fmt.Println(res.ConversationID, res.QueryID, res.Model)
fmt.Println(res.Answer)Pass nil instead of options to use the defaults. Cancel with the context.
Things to know
- An empty prompt is rejected before any request is sent (
TypeErrorin TypeScript,SafeguardErrorin Python, an error in Go). - A query that the service has started is never sent again by the SDK, so a dropped connection raises instead of asking twice. See Errors and retries.
- A query runs as the key's member and counts against the workspace's Safeguard AI run capacity. See Rate and usage limits.