Staso Docs
Reference

Every public symbol in staso with its exact signature. Paste this page to an LLM to get correct setup code on the first try.

import staso as st

All examples in this file assume that alias.

Initialization

SymbolSignatureDescription
st.initst.init(*, api_key=None, agent_name=None, base_url=None, batch_size=100, flush_interval=5.0, max_queue_size=10_000, enabled=True, debug=None, environment=None, workspace_slug=None, capture_messages=True, capture_git=True) -> ClientInitialize the global Staso client. Raises ValueError if api_key or agent_name is missing.
st.shutdownst.shutdown() -> NoneFlush pending spans and stop the background transport. Auto-registered via atexit.
st.get_clientst.get_client() -> Client | NoneReturn the globally initialized client, or None before init.
st.generate_agent_idst.generate_agent_id(agent_name: str) -> strDeterministic UUID5 for an agent name — same shape the backend stores.

See Initialization for setup walkthroughs.

Decorators

All decorators support both @st.x and @st.x(...) call styles. They work on both sync and async def functions.

SymbolSignatureDescription
st.agentst.agent(_fn=None, name=None, *, tags=None, metadata=None, capture_input=True, capture_output=True)Wrap an agent entry-point in a kind="agent" span and bind agent_name to the context.
st.toolst.tool(_fn=None, name=None, *, tags=None, metadata=None, capture_input=True, capture_output=True)Wrap a tool function in a kind="tool" span.
st.tracest.trace(_fn=None, name=None, *, kind=SpanKind.CHAIN, tags=None, metadata=None, capture_input=True, capture_output=True)Generic span decorator for arbitrary functions. Exported as trace but defined as trace_fn.

See Decorators.

Context managers

SymbolSignatureDescription
st.spanwith st.span(name: str, *, kind: str | SpanKind = SpanKind.CHAIN) as s:Create a manual span. Yields a Span instance.
st.conversationwith st.conversation(conversation_id: str | None = None, *, user_id: str | None = None):Group every span in scope under one conversation_id. Auto-generates a UUID if conversation_id is omitted.

Span instance methods

Inside with st.span(...) as s: or any decorated function, these methods are available on the span object:

Method / fieldSignatureDescription
s.set_statuss.set_status(status: SpanStatus, description: str | None = None) -> NoneMark the span as OK, ERROR, or TIMEOUT.
s.record_exceptions.record_exception(exception: BaseException) -> NoneRecord an exception and flip status to ERROR.
s.annotates.annotate(name: str, *, value: float | str | bool, data_type: str = "numeric", comment: str | None = None) -> NoneAttach an annotation scoped to this span's trace.
s.inputdict[str, Any]Free-form request payload. Serialized to JSON on flush.
s.outputdict[str, Any]Free-form response payload.
s.metadatadict[str, Any]Well-known keys listed in Data Model.
s.model, s.input_tokens, s.output_tokens, s.total_tokensLLM-specific top-level columns.

Annotations

SymbolSignatureDescription
st.annotatest.annotate(*, trace_id: str, name: str, value: float | str | bool, data_type: str | AnnotationDataType = AnnotationDataType.NUMERIC, span_id: str | None = None, comment: str | None = None) -> NoneAttach a score or label to a trace. Fire-and-forget — HTTP errors are logged, not raised.
st.AnnotationDataTypeStrEnum("numeric", "categorical", "boolean")Allowed annotation value types.

See Annotations.

Guard

SymbolSignatureDescription
st.guardst.guard(tool_name: str, tool_input: dict[str, Any], *, context: dict | None = None, wait_for_escalation: bool = False, escalation_poll_interval: float = 3.0, escalation_timeout: float = 300.0, timeout: float = 10.0, fail_closed: bool | None = None) -> GuardResultEvaluate a tool action before executing it. Fail-open by default — set fail_closed=True or STASO_GUARD_FAIL_CLOSED=true for strict mode.
st.GuardResultdataclass(frozen=True) with fields: action: str, reason: str = "", rule_name: str | None = None, severity: str = "low", results: list[GuardRuleResult], modified_input: dict | None, modifications: list[dict], escalation_id: str | None, latency_ms: float, rules_triggered: list[str]Result of a guard check. action is one of "allow" | "block" | "modify" | "escalate".
st.GuardBlockedException with attributes: tool_name: str, result: GuardResult, reason: str, rules_triggered: list[str], blocked_tools: list[BlockedTool]Raised by patch_openai / patch_anthropic when an enforce-mode rule fires. Catches at the LLM-call site.
st.BlockedTooldataclass(frozen=True) with fields: tool_name: str, result: GuardResultOne entry in GuardBlocked.blocked_tools.

See Manual guard checks and Enforcement.

Integrations

Auto-instrument LLM client libraries. Call once after st.init().

SymbolSignatureDescription
staso.integrations.patch_anthropicpatch_anthropic() -> NoneAuto-instrument the Anthropic SDK (anthropic.Anthropic, AsyncAnthropic, streaming, tool use).
staso.integrations.patch_openaipatch_openai() -> NoneAuto-instrument the OpenAI SDK (openai.OpenAI, AsyncOpenAI, chat completions, streaming, tool calls).

See Integrations.

Dataset module

Import as import staso as st — every function is a top-level attribute on st.dataset. import staso.dataset also returns the real module.

CRUD

SymbolSignature
st.dataset.createcreate(name: str, *, description: str = "", columns: list[dict[str, str]] | None = None, folder_id: str | None = None) -> Dataset
st.dataset.getget(dataset_id: str) -> Dataset
st.dataset.listlist(*, folder_id: str | None = None, limit: int = 100, offset: int = 0) -> list[Dataset]
st.dataset.updateupdate(dataset_id: str, *, name: str | None = None, description: str | None = None) -> Dataset
st.dataset.deletedelete(dataset_id: str) -> None

Entries

SymbolSignature
st.dataset.add_entryadd_entry(dataset_id: str, data: dict[str, Any], *, split: str | SplitType | None = None, source_trace_id: str | None = None, source_span_id: str | None = None) -> DatasetEntry
st.dataset.add_entriesadd_entries(dataset_id: str, entries: list[dict[str, Any]], *, split: str | SplitType | None = None) -> list[DatasetEntry]
st.dataset.list_entrieslist_entries(dataset_id: str, *, split: str | SplitType | None = None, limit: int = 100, offset: int = 0) -> list[DatasetEntry]
st.dataset.update_entryupdate_entry(dataset_id: str, entry_id: str, *, data: dict[str, Any] | None = None) -> DatasetEntry
st.dataset.delete_entrydelete_entry(dataset_id: str, entry_id: str) -> None

CSV

SymbolSignature
st.dataset.upload_csvupload_csv(dataset_id: str, file_path: str | Path, *, split: str | SplitType | None = None) -> int
st.dataset.download_csvdownload_csv(dataset_id: str, file_path: str | Path, *, split: str | SplitType | None = None) -> Path

From traces

SymbolSignature
st.dataset.from_tracesfrom_traces(name: str, trace_ids: list[str], *, mapping: list[TraceColumnMapping] | dict[str, str] | None = None, description: str = "") -> Dataset
st.dataset.TraceColumnMappingdataclass(frozen=True) with fields: source: str, target: str

Evaluation

SymbolSignature
st.dataset.evaluateevaluate(dataset_id: str, fn: Callable[[dict[str, Any]], Any], *, scorers: list[Callable[[dict, Any], float]] | None = None, split: str | SplitType | None = None, max_concurrency: int = 1, trace: bool = True) -> EvalSummary
st.EvalResultdataclass(frozen=True)entry_id, input_data, expected, actual, scores: dict[str, float], passed: bool, error: str | None, trace_id: str | None, duration_ms: float
st.EvalSummarydataclass(frozen=True)dataset_id, dataset_name, total, passed, failed, error_count, avg_duration_ms, scores: dict[str, float], results: tuple[EvalResult, ...]

Synthetic

SymbolSignature
st.dataset.generategenerate(dataset_id: str, *, count: int = 10, prompt: str | None = None, seed_entry_ids: list[str] | None = None) -> list[DatasetEntry]

Folders

SymbolSignature
st.dataset.create_foldercreate_folder(name: str, *, parent_id: str | None = None) -> DatasetFolder
st.dataset.list_folderslist_folders(*, parent_id: str | None = None) -> list[DatasetFolder]
st.dataset.delete_folderdelete_folder(folder_id: str) -> None

Types

SymbolFields
st.Datasetid, name, description, folder_id, template, columns: tuple[DatasetColumn, ...], entry_count, created_at, updated_at
st.DatasetEntryid, dataset_id, data: dict[str, Any], split: str | None, source_type: str | None, created_at
st.DatasetColumnname, column_type: str = "variable", description, required: bool = False
st.DatasetFolderid, name, parent_id: str | None
st.ColumnTypeStrEnumvariable, input, output, expected_output, expected_tool_calls, scenario, expected_steps, conversation_history, files, custom
st.SplitTypeStrEnumtrain, test, validation
st.StasoDatasetErrorExceptionmessage, status_code: int | None, response_body: str

See Datasets and Evaluation.

Types

SymbolValues
st.SpanKindStrEnumLLM, TOOL, CHAIN, RETRIEVER, AGENT, CUSTOM
st.SpanStatusStrEnumOK, ERROR, TIMEOUT

See Data Model for field-by-field semantics.

Configuration objects

SymbolDescription
st.ClientThe object returned by st.init. Holds the transport and config. Users rarely construct this directly.
st.Configdataclass(frozen=True) — full field list: api_key, agent_name, agent_id, base_url, batch_size=100, flush_interval=5.0, max_queue_size=10_000, enabled=True, debug=False, environment="default", workspace_slug="default", capture_messages=True, git_context
st.SpanThe span class yielded by st.span and by decorators. Fields listed above under Context managers.

Errors

ExceptionRaised byWhen
st.GuardBlockedpatch_openai, patch_anthropicAn enforce-mode guard rule blocked one or more tool calls.
st.StasoDatasetErrorst.dataset.*Backend returned a non-2xx response (status_code, response_body on the exception).
ValueErrorst.init, st.annotateMissing api_key/agent_name, or annotation value type mismatch.

Environment variables

See Environment Variables for the complete list of STASO_* variables read by the SDK, CLI, and integrations.

Version

SymbolDescription
staso.__version__Installed SDK version string.