Skip to Content

Models

Pydantic response models returned by the CT SDK.

All models use extra='ignore' — new server fields never break older SDK versions. Fields use snake_case throughout.

from kaizen_sdk.models import Task, FeedbackResult, Prompt, Job, OptimizeResult, CostEstimate, TraceResult

Task

A tuning task (e.g. "summarize_ticket") with its configuration and current status.

class Task(BaseModel): ...

Fields

FieldTypeDefaultDescription
iduuid.UUIDrequiredUnique task identifier.
namestrrequiredHuman-readable task name (e.g. "summarize_ticket").
descriptionstr | NoneNoneOptional description of what the task does.
task_schemadict | NoneNoneJSON schema for expected input structure. (API alias: schema_json)
feedback_thresholdintrequiredNumber of feedback entries before auto-optimization triggers.
feedback_retention_limitint1000Maximum feedback entries to retain per task.
evaluator_configdict | NoneNoneCustom evaluator configuration.
teacher_modelstr | NoneNoneLLM used as teacher during optimization (e.g. "gpt-4o").
judge_modelstr | NoneNoneLLM used to judge prompt quality (e.g. "gpt-4o-mini").
module_typestr"predict"DSPy module type.
cost_budgetfloat | NoneNoneMaximum USD to spend per optimization run.
github_repostr | NoneNoneGit repository for auto-PR (e.g. "org/repo").
github_base_branchstr | NoneNoneBase branch for PRs (e.g. "main").
prompt_pathstr | NoneNoneFile path where the optimized prompt is written.
prompt_formatstr | NoneNoneFormat for the prompt file (e.g. "python", "text").
created_atdatetimerequiredTimestamp when the task was created.
feedback_countint0Total feedback entries logged for this task.
last_optimizationdatetime | NoneNoneWhen the most recent optimization run completed.
active_prompt_scorefloat | NoneNoneEval score of the currently active prompt version.
threshold_progressstr"0/50"Human-readable progress toward feedback threshold (e.g. "42/50").

Example

with CTClient() as client: task = client.create_task(name="summarize_ticket", feedback_threshold=100) print(task.id) # uuid.UUID print(task.threshold_progress) # "0/100"

FeedbackResult

A single feedback entry logged for a task.

class FeedbackResult(BaseModel): ...

Fields

FieldTypeDefaultDescription
iduuid.UUIDrequiredUnique feedback entry identifier.
task_iduuid.UUIDrequiredTask this feedback belongs to.
inputsdict | NoneNoneInput variables that were passed to the LLM.
outputstr | NoneNoneLLM output text that was evaluated.
scorefloat | NoneNoneQuality score in [0.0, 1.0].
sourcestr | NoneNoneSource label (e.g. "sdk", "human", "auto").
metadatadict | NoneNoneArbitrary metadata attached to this entry. (API alias: metadata_)
created_atdatetimerequiredTimestamp when the feedback was logged.

Example

with CTClient() as client: result = client.log_feedback( task_id=str(task.id), inputs={"ticket": "Login broken"}, output="User cannot log in.", score=0.95, ) print(result.id) # uuid.UUID print(result.created_at)

Prompt

A prompt version produced by optimization (or the initial baseline).

class Prompt(BaseModel): ...

PromptVersion is an alias for Prompt used in listing contexts. They are the same type.

Fields

FieldTypeDefaultDescription
iduuid.UUIDrequiredUnique prompt version identifier.
task_iduuid.UUIDrequiredTask this prompt version belongs to.
version_numberintrequiredMonotonically increasing version number.
prompt_textstr | NoneNoneThe full prompt template text.
eval_scorefloat | NoneNoneEvaluation score achieved by this version.
statusstrrequiredVersion status: "active", "candidate", "archived".
optimizerstr | NoneNoneOptimizer that produced this version (e.g. "MIPROv2").
dspy_versionstr | NoneNoneDSPy version used during optimization.
created_atdatetimerequiredTimestamp when this prompt version was created.

Example

with CTClient() as client: prompt = client.get_prompt(str(task.id)) print(prompt.prompt_text) print(f"v{prompt.version_number} — score: {prompt.eval_score}")

Job

An optimization job (running or completed).

class Job(BaseModel): ...

Fields

FieldTypeDefaultDescription
iduuid.UUIDrequiredUnique job identifier.
task_iduuid.UUIDrequiredTask being optimized.
prompt_version_iduuid.UUID | NoneNoneThe prompt version produced by this job (set on completion).
statusstrrequiredJob status: "PENDING", "RUNNING", "EVALUATING", "COMPILING", "SUCCESS", "FAILURE", "PR_FAILED".
triggered_bystr | NoneNoneHow the job was triggered ("api", "threshold", "webhook").
feedback_countint | NoneNoneNumber of feedback entries used for this run.
pr_urlstr | NoneNonePull request URL if auto-PR was created.
error_messagestr | NoneNoneError detail if status == "FAILURE" or "PR_FAILED".
job_metadatadict | NoneNoneInternal metadata from the optimization run.
progress_stepstr | NoneNoneHuman-readable current step (e.g. "Compiling with MIPROv2...").
started_atdatetime | NoneNoneWhen the job started running.
completed_atdatetime | NoneNoneWhen the job completed or failed.
created_atdatetimerequiredWhen the job was created.

Example

with CTClient() as client: job = client.get_job(str(optimize_result.job.id)) print(f"{job.status}: {job.progress_step}") if job.status == "SUCCESS": print(f"PR: {job.pr_url}") elif job.status in ("FAILURE", "PR_FAILED"): print(f"Error: {job.error_message}")

OptimizeResult

Returned by trigger_optimization(). Contains the queued job and a cost estimate.

class OptimizeResult(BaseModel): ...

Fields

FieldTypeDefaultDescription
jobJobrequiredThe optimization job that was created.
cost_estimateCostEstimaterequiredEstimated cost for this optimization run.
budget_warningstr | NoneNoneWarning message if estimated cost exceeds the task’s cost_budget.

Example

with CTClient() as client: result = client.trigger_optimization(str(task.id)) print(f"Job: {result.job.id}, Status: {result.job.status}") print(f"Cost: ${result.cost_estimate.estimated_cost_usd:.4f}") if result.budget_warning: print(f"⚠ {result.budget_warning}")

CostEstimate

Estimated resource usage for an optimization run.

class CostEstimate(BaseModel): ...

Fields

FieldTypeDescription
estimated_cost_usdfloatEstimated total USD cost for the optimization run.
estimated_llm_callsintEstimated number of LLM API calls.
train_sizeintNumber of feedback entries used for training.
val_sizeintNumber of feedback entries used for validation.
max_trialsintMaximum optimization trials planned.
teacher_modelstrTeacher model that will be used (e.g. "gpt-4o").
judge_modelstrJudge model that will be used (e.g. "gpt-4o-mini").

TraceResult

A trace captured by the auto-instrument SDK.

class TraceResult(BaseModel): ...

Fields

FieldTypeDefaultDescription
iduuid.UUIDrequiredUnique trace identifier.
task_iduuid.UUIDrequiredTask this trace belongs to.
prompt_textstr | NoneNoneThe prompt text sent to the LLM.
response_textstr | NoneNoneThe LLM’s response text.
modelstr | NoneNoneModel name (e.g. "gpt-4o-mini").
tokensint | NoneNoneTotal tokens used in the LLM call.
latency_msfloat | NoneNoneEnd-to-end latency in milliseconds.
source_filestr | NoneNoneSource file where the LLM call was made.
source_variablestr | NoneNoneVariable name holding the prompt in source code.
scorefloat | NoneNoneQuality score applied to this trace (if scored).
scored_bystr | NoneNoneWho/what scored the trace (e.g. "sdk", "human").
created_atdatetimerequiredTimestamp when the trace was captured.

Example

# TraceResult is returned by CTClient.score() with CTClient() as client: trace = client.score( trace_id=response.ct_trace_id, score=0.9, scored_by="human", ) print(f"Trace {trace.id}: score={trace.score}, latency={trace.latency_ms}ms")
Last updated on