API Reference¶
Complete API documentation for StringSight's main functions and classes.
Main Entry Points¶
explain()¶
explain(df, method='single_model', system_prompt=None, prompt_builder=None, task_description=None, *, sample_size=None, model_a=None, model_b=None, score_columns=None, prompt_column='prompt', model_column=None, model_response_column=None, question_id_column=None, model_a_column=None, model_b_column=None, model_a_response_column=None, model_b_response_column=None, model_name='gpt-4.1', temperature=0.7, top_p=0.95, max_tokens=16000, max_workers=DEFAULT_MAX_WORKERS, include_scores_in_prompt=False, prompt_expansion=False, expansion_num_traces=5, expansion_model='gpt-4.1', use_dynamic_prompts=True, dynamic_prompt_samples=5, dynamic_prompt_model=None, clusterer='hdbscan', min_cluster_size=5, embedding_model='text-embedding-3-large', prettify_labels=False, assign_outliers=False, summary_model='gpt-4.1', cluster_assignment_model='gpt-4.1-mini', metrics_kwargs=None, use_wandb=True, wandb_project=None, include_embeddings=False, verbose=False, output_dir=None, custom_pipeline=None, extraction_cache_dir=None, clustering_cache_dir=None, metrics_cache_dir=None, progress_callback=None, **kwargs)
¶
Explain model behavior patterns from conversation data.
This is the main entry point for StringSight. It takes a DataFrame of conversations and returns the same data with extracted properties and clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with conversation data |
required |
method
|
str
|
"side_by_side" or "single_model" |
'single_model'
|
system_prompt
|
str | None
|
System prompt for property extraction (if None, will be auto-determined) |
None
|
prompt_builder
|
Callable[[Series, str], str] | None
|
Optional custom prompt builder function |
None
|
task_description
|
str | None
|
Optional description of the task; when provided with method="single_model" and no explicit system_prompt, a task-aware system prompt is constructed from single_model_system_prompt_custom. If prompt_expansion=True, this description will be expanded using example traces before being used in prompts. |
None
|
sample_size
|
int | None
|
Optional number of rows to sample from the dataset before processing. If None, uses the entire dataset. For single_model method with balanced datasets (each prompt answered by all models), automatically samples prompts evenly across models. Otherwise falls back to row-level sampling. |
None
|
model_a
|
str | None
|
For side_by_side method with tidy data, specifies first model to select |
None
|
model_b
|
str | None
|
For side_by_side method with tidy data, specifies second model to select |
None
|
score_columns
|
List[str] | None
|
Optional list of column names containing score metrics. Instead of providing scores as a dictionary in a 'score' column, you can specify separate columns for each metric. For single_model: columns should be named like 'accuracy', 'helpfulness'. For side_by_side: columns should be named like 'accuracy_a', 'accuracy_b', 'helpfulness_a', 'helpfulness_b'. If provided, these columns will be converted to the expected score dict format. |
None
|
prompt_column
|
str
|
Name of the prompt column in your dataframe (default: "prompt") |
'prompt'
|
model_column
|
str | None
|
Name of the model column for single_model (default: "model") |
None
|
model_response_column
|
str | None
|
Name of the model response column for single_model (default: "model_response") |
None
|
question_id_column
|
str | None
|
Name of the question_id column (default: "question_id" if column exists) |
None
|
model_a_column
|
str | None
|
Name of the model_a column for side_by_side (default: "model_a") |
None
|
model_b_column
|
str | None
|
Name of the model_b column for side_by_side (default: "model_b") |
None
|
model_a_response_column
|
str | None
|
Name of the model_a_response column for side_by_side (default: "model_a_response") |
None
|
model_b_response_column
|
str | None
|
Name of the model_b_response column for side_by_side (default: "model_b_response") |
None
|
model_name
|
str
|
LLM model for property extraction |
'gpt-4.1'
|
temperature
|
float
|
Temperature for LLM |
0.7
|
top_p
|
float
|
Top-p for LLM |
0.95
|
max_tokens
|
int
|
Max tokens for LLM |
16000
|
max_workers
|
int
|
Max parallel workers for API calls |
DEFAULT_MAX_WORKERS
|
prompt_expansion
|
bool
|
If True, expand task_description using example traces before extraction (default: False) |
False
|
expansion_num_traces
|
int
|
Number of traces to sample for expansion (default: 5) |
5
|
expansion_model
|
str
|
LLM model to use for expansion (default: "gpt-4.1") |
'gpt-4.1'
|
clusterer
|
Union[str, Any]
|
Clustering method ("hdbscan", "hdbscan_native") or PipelineStage |
'hdbscan'
|
min_cluster_size
|
int | None
|
Minimum cluster size |
5
|
embedding_model
|
str
|
Embedding model ("openai" or sentence-transformer model) |
'text-embedding-3-large'
|
assign_outliers
|
bool
|
Whether to assign outliers to nearest clusters |
False
|
summary_model
|
str
|
LLM model for generating cluster summaries (default: "gpt-4.1") |
'gpt-4.1'
|
cluster_assignment_model
|
str
|
LLM model for assigning outliers to clusters (default: "gpt-4.1-mini") |
'gpt-4.1-mini'
|
metrics_kwargs
|
Dict[str, Any | None] | None
|
Additional metrics configuration |
None
|
use_wandb
|
bool
|
Whether to log to Weights & Biases |
True
|
wandb_project
|
str | None
|
W&B project name |
None
|
include_embeddings
|
bool
|
Whether to include embeddings in output |
False
|
verbose
|
bool
|
Whether to print progress |
False
|
output_dir
|
str | None
|
Directory to save results (optional). If provided, saves: - clustered_results.parquet: DataFrame with all results - full_dataset.json: Complete PropertyDataset (JSON format) - full_dataset.parquet: Complete PropertyDataset (parquet format) - model_stats.json: Model statistics and rankings - summary.txt: Human-readable summary |
None
|
custom_pipeline
|
Pipeline | None
|
Custom pipeline to use instead of default |
None
|
**kwargs
|
Any
|
Additional configuration options |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Tuple of (clustered_df, model_stats) |
Dict[str, DataFrame]
|
|
Tuple[DataFrame, Dict[str, DataFrame]]
|
|
Notes on input format
- For method="single_model": expect columns [question_id, prompt, model, model_response, (optional) score]
- For method="side_by_side": expect columns [question_id, prompt, model_a, model_b, model_a_response, model_b_response]
- Alternatively, for method="side_by_side" you may pass tidy single-model-like data
(columns [prompt, model, model_response] and optionally question_id) and specify
model_aandmodel_bparameters. The function will select these two models and convert the input to the expected side-by-side schema.
Example
import pandas as pd from stringsight import explain
Load your conversation data¶
df = pd.read_csv("conversations.csv")
Explain model behavior and save results¶
clustered_df, model_stats = explain( ... df, ... method="side_by_side", ... min_cluster_size=5, ... output_dir="results/" # Automatically saves results ... )
Explore the results¶
print(clustered_df.columns) print(model_stats.keys())
Source code in stringsight/_public/sync_api.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
label()¶
label(df, *, taxonomy, sample_size=None, score_columns=None, prompt_column='prompt', model_column=None, model_response_column=None, question_id_column=None, model_name='gpt-4.1', temperature=0.0, top_p=1.0, max_tokens=2048, max_workers=DEFAULT_MAX_WORKERS, metrics_kwargs=None, use_wandb=True, wandb_project=None, include_embeddings=False, verbose=False, output_dir=None, extraction_cache_dir=None, metrics_cache_dir=None, **kwargs)
¶
Run the fixed-taxonomy analysis pipeline. This is just you're run of the mill LLM-judge with a given rubric.
The user provides a dataframe with a model and its responses alone with a taxonomy.
Unlike :pyfunc:explain, this entry point does not perform clustering;
each taxonomy label simply becomes its own cluster. The input df must
be in single-model format (columns question_id, prompt, model, model_response, …).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with single-model conversation data |
required |
taxonomy
|
Dict[str, str]
|
Dictionary mapping label names to their descriptions |
required |
sample_size
|
int | None
|
Optional number of rows to sample from the dataset before processing. If None, uses the entire dataset. For balanced datasets (each prompt answered by all models), automatically samples prompts evenly across models. |
None
|
score_columns
|
List[str] | None
|
Optional list of column names containing score metrics. Instead of providing scores as a dictionary in a 'score' column, you can specify separate columns for each metric (e.g., ['accuracy', 'helpfulness']). If provided, these columns will be converted to the expected score dict format. |
None
|
prompt_column
|
str
|
Name of the prompt column in your dataframe (default: "prompt") |
'prompt'
|
model_column
|
str | None
|
Name of the model column (default: "model") |
None
|
model_response_column
|
str | None
|
Name of the model response column (default: "model_response") |
None
|
question_id_column
|
str | None
|
Name of the question_id column (default: "question_id" if column exists) |
None
|
model_name
|
str
|
LLM model for property extraction (default: "gpt-4.1") |
'gpt-4.1'
|
temperature
|
float
|
Temperature for LLM (default: 0.0) |
0.0
|
top_p
|
float
|
Top-p for LLM (default: 1.0) |
1.0
|
max_tokens
|
int
|
Max tokens for LLM (default: 2048) |
2048
|
max_workers
|
int
|
Max parallel workers for API calls (default: 16) |
DEFAULT_MAX_WORKERS
|
metrics_kwargs
|
Dict[str, Any | None] | None
|
Additional metrics configuration |
None
|
use_wandb
|
bool
|
Whether to log to Weights & Biases (default: True) |
True
|
wandb_project
|
str | None
|
W&B project name |
None
|
include_embeddings
|
bool
|
Whether to include embeddings in output (default: True) |
False
|
verbose
|
bool
|
Whether to print progress (default: True) |
False
|
output_dir
|
str | None
|
Directory to save results (optional) |
None
|
extraction_cache_dir
|
str | None
|
Cache directory for extraction results |
None
|
metrics_cache_dir
|
str | None
|
Cache directory for metrics results |
None
|
**kwargs
|
Any
|
Additional configuration options |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Tuple of (clustered_df, model_stats) |
Dict[str, DataFrame]
|
|
Tuple[DataFrame, Dict[str, DataFrame]]
|
|
Source code in stringsight/_public/label_api.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
extract_properties_only()¶
extract_properties_only(df, *, method='single_model', system_prompt=None, task_description=None, fail_on_empty_properties=True, score_columns=None, sample_size=None, model_a=None, model_b=None, prompt_column='prompt', model_column=None, model_response_column=None, question_id_column=None, model_a_column=None, model_b_column=None, model_a_response_column=None, model_b_response_column=None, model_name='gpt-4.1', temperature=0.7, top_p=0.95, max_tokens=16000, max_workers=DEFAULT_MAX_WORKERS, include_scores_in_prompt=False, use_wandb=True, wandb_project=None, verbose=False, output_dir=None, extraction_cache_dir=None, return_debug=False)
¶
Run only the extraction → parsing → validation stages and return a PropertyDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input conversations dataframe (single_model or side_by_side format) |
required |
method
|
str
|
"single_model" | "side_by_side" |
'single_model'
|
system_prompt
|
str | None
|
Explicit system prompt text or a short prompt name from stringsight.prompts |
None
|
task_description
|
str | None
|
Optional task-aware description (used only if the chosen prompt has {task_description}) |
None
|
fail_on_empty_properties
|
bool
|
If True, raise a RuntimeError when 0 valid properties remain after validation. If False, return an empty PropertyDataset.properties list. |
True
|
score_columns
|
List[str] | None
|
Optional list of column names containing score metrics to convert to dict format |
None
|
sample_size
|
int | None
|
Optional number of rows to sample from the dataset before processing |
None
|
model_a
|
str | None
|
For side_by_side method with tidy data, specifies first model to select |
None
|
model_b
|
str | None
|
For side_by_side method with tidy data, specifies second model to select |
None
|
prompt_column
|
str
|
Name of the prompt column in your dataframe (default: "prompt") |
'prompt'
|
model_column
|
str | None
|
Name of the model column for single_model (default: "model") |
None
|
model_response_column
|
str | None
|
Name of the model response column for single_model (default: "model_response") |
None
|
question_id_column
|
str | None
|
Name of the question_id column (default: "question_id" if column exists) |
None
|
model_a_column
|
str | None
|
Name of the model_a column for side_by_side (default: "model_a") |
None
|
model_b_column
|
str | None
|
Name of the model_b column for side_by_side (default: "model_b") |
None
|
model_a_response_column
|
str | None
|
Name of the model_a_response column for side_by_side (default: "model_a_response") |
None
|
model_b_response_column
|
str | None
|
Name of the model_b_response column for side_by_side (default: "model_b_response") |
None
|
model_name, temperature, top_p, max_tokens, max_workers
|
LLM config for extraction |
required | |
include_scores_in_prompt
|
bool
|
Whether to include any provided score fields in the prompt context |
False
|
use_wandb, wandb_project, verbose
|
Logging configuration |
required | |
output_dir
|
str | None
|
If provided, stages will auto-save their artefacts to this directory |
None
|
extraction_cache_dir
|
str | None
|
Optional cache directory for extractor |
None
|
Returns:
| Type | Description |
|---|---|
PropertyDataset | tuple[PropertyDataset, list[dict[str, Any]]]
|
PropertyDataset containing parsed Property objects (no clustering or metrics). |
Source code in stringsight/_public/sync_api.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
compute_metrics_only()¶
compute_metrics_only(input_path, method='single_model', output_dir=None, metrics_kwargs=None, use_wandb=True, verbose=False)
¶
Run only the metrics computation stage on existing pipeline results.
This function loads existing pipeline results (from extraction and clustering stages) and runs only the metrics computation stage. Useful for: - Recomputing metrics with different parameters - Running metrics on results from previous pipeline runs - Debugging metrics computation without re-running the full pipeline
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
str
|
Path to existing pipeline results (file or directory) |
required |
method
|
str
|
"single_model" or "side_by_side" |
'single_model'
|
output_dir
|
str | None
|
Directory to save metrics results (optional) |
None
|
metrics_kwargs
|
Dict[str, Any | None] | None
|
Additional arguments for metrics computation |
None
|
use_wandb
|
bool
|
Whether to enable wandb logging |
True
|
verbose
|
bool
|
Whether to print verbose output |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[DataFrame, Dict[str, Any]]
|
Tuple of (clustered_df, model_stats) |
Example
from stringsight import compute_metrics_only
Run metrics on existing pipeline results¶
clustered_df, model_stats = compute_metrics_only( ... input_path="results/previous_run/full_dataset.json", ... method="single_model", ... output_dir="results/metrics_only" ... )
Or run on a directory containing pipeline outputs¶
clustered_df, model_stats = compute_metrics_only( ... input_path="results/previous_run/", ... method="side_by_side" ... )
Source code in stringsight/_public/metrics_only.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
Convenience Functions¶
explain_side_by_side()¶
explain_side_by_side(df, system_prompt=None, tidy_side_by_side_models=None, **kwargs)
¶
Convenience function for side-by-side model comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with columns: model_a, model_b, model_a_response, model_b_response, winner |
required |
system_prompt
|
str | None
|
System prompt for extraction (if None, will be auto-determined) |
None
|
**kwargs
|
Any
|
Additional arguments passed to explain() |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[DataFrame, Dict[str, DataFrame]]
|
Tuple of (clustered_df, model_stats) |
Source code in stringsight/_public/convenience.py
explain_single_model()¶
explain_single_model(df, system_prompt=None, **kwargs)
¶
Convenience function for single model analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with columns: model, model_response, score |
required |
system_prompt
|
str | None
|
System prompt for extraction (if None, will be auto-determined) |
None
|
**kwargs
|
Any
|
Additional arguments passed to explain() |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[DataFrame, Dict[str, DataFrame]]
|
Tuple of (clustered_df, model_stats) |
Source code in stringsight/_public/convenience.py
explain_with_custom_pipeline()¶
explain_with_custom_pipeline(df, pipeline, method='single_model')
¶
Explain model behavior using a custom pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with conversation data |
required |
pipeline
|
Pipeline
|
Custom pipeline to use |
required |
method
|
str
|
"side_by_side" or "single_model" |
'single_model'
|
Returns:
| Type | Description |
|---|---|
Tuple[DataFrame, Dict[str, Any]]
|
Tuple of (clustered_df, model_stats) |
Source code in stringsight/_public/convenience.py
Core Data Structures¶
PropertyDataset¶
PropertyDataset
dataclass
¶
Container for all data flowing through the pipeline.
This is the single data contract between all pipeline stages.
Source code in stringsight/core/data_objects.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | |
from_dataframe(df, method='single_model')
classmethod
¶
Create PropertyDataset from existing DataFrame formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame with conversation data |
required |
method
|
str
|
"side_by_side" for comparison data, "single_model" for single responses |
'single_model'
|
Returns:
| Type | Description |
|---|---|
PropertyDataset
|
PropertyDataset with populated conversations |
Source code in stringsight/core/data_objects.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
save(path, format='json', storage=None)
¶
Save the dataset to path in either json, dataframe, parquet or pickle format.
The JSON variant produces a fully human-readable file while the pickle variant preserves the exact Python objects.
Source code in stringsight/core/data_objects.py
load(path, format='json', storage=None)
classmethod
¶
Load a dataset previously saved with :py:meth:save.
Source code in stringsight/core/data_objects.py
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | |
to_dataframe(type='all', method='side_by_side')
¶
Convert PropertyDataset back to DataFrame format.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with original data plus extracted properties and clusters |
Source code in stringsight/core/data_objects.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
ConversationRecord¶
ConversationRecord
dataclass
¶
A single conversation with prompt, responses, and metadata.
Source code in stringsight/core/data_objects.py
__post_init__()
¶
Migrate legacy score formats to the new list format for side-by-side.
Source code in stringsight/core/data_objects.py
Property¶
Property
dataclass
¶
An extracted behavioral property from a model response.
Source code in stringsight/core/data_objects.py
__post_init__()
¶
Validate property fields after initialization.
Source code in stringsight/core/data_objects.py
Cluster¶
Cluster
dataclass
¶
A cluster of properties.
Source code in stringsight/core/data_objects.py
__post_init__()
¶
Ensure consistent types.
Source code in stringsight/core/data_objects.py
to_sample_dict(n=5)
¶
Return a dictionary that samples n property descriptions and ids from the cluster.
Source code in stringsight/core/data_objects.py
Pipeline Components¶
PipelineStage¶
PipelineStage
¶
Bases: ABC
Abstract base class for all pipeline stages.
Each stage takes a PropertyDataset as input and returns a PropertyDataset as output. This allows stages to be composed into pipelines.
Source code in stringsight/core/stage.py
__init__(*args, **kwargs)
¶
Initialize the stage with configuration parameters and propagate to mixins.
Source code in stringsight/core/stage.py
run(data, progress_callback=None, **kwargs)
abstractmethod
¶
Process the input data and return the modified data.
Can be either sync or async (returning PropertyDataset or Coroutine[Any, Any, PropertyDataset]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PropertyDataset
|
Input PropertyDataset |
required |
progress_callback
|
Any
|
Optional callback(completed, total) for progress updates |
None
|
**kwargs
|
Any
|
Additional keyword arguments specific to the stage implementation |
{}
|
Returns:
| Type | Description |
|---|---|
PropertyDataset | Any
|
Modified PropertyDataset (or Coroutine that resolves to PropertyDataset for async stages) |
Source code in stringsight/core/stage.py
validate_input(data)
¶
Validate that the input data meets the requirements for this stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PropertyDataset
|
Input PropertyDataset |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input data is invalid |
Source code in stringsight/core/stage.py
validate_output(data)
¶
Validate that the output data is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PropertyDataset
|
Output PropertyDataset |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the output data is invalid |
Source code in stringsight/core/stage.py
__call__(data, progress_callback=None)
async
¶
Convenience method to run the stage.
This allows stages to be called directly: stage(data) or await stage(data) Handles both sync and async run() methods automatically.
Source code in stringsight/core/stage.py
Pipeline¶
Pipeline
¶
Bases: LoggingMixin, TimingMixin, ErrorHandlingMixin, WandbMixin
A pipeline for processing data through multiple stages.
The Pipeline class coordinates the execution of multiple pipeline stages, handles error recovery, and provides logging and timing information.
Source code in stringsight/pipeline.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
run(data, progress_callback=None)
async
¶
Execute all stages in the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PropertyDataset
|
Input PropertyDataset |
required |
progress_callback
|
Any
|
Optional callback(float) -> None to report progress (0.0-1.0) |
None
|
Returns:
| Type | Description |
|---|---|
PropertyDataset
|
PropertyDataset after processing through all stages |
Source code in stringsight/pipeline.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
add_stage(stage)
¶
Add a stage to the end of the pipeline.
Source code in stringsight/pipeline.py
Extractors¶
get_extractor()¶
get_extractor(model_name='gpt-4.1-mini', system_prompt='one_sided_system_prompt', prompt_builder=None, temperature=0.6, top_p=0.95, max_tokens=16000, max_workers=DEFAULT_MAX_WORKERS, include_scores_in_prompt=False, **kwargs)
¶
Factory function to get the appropriate extractor based on model name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the LLM to use for extraction |
'gpt-4.1-mini'
|
system_prompt
|
str
|
System prompt for property extraction |
'one_sided_system_prompt'
|
prompt_builder
|
Optional[Callable]
|
Optional custom prompt builder function |
None
|
temperature
|
float
|
Temperature for LLM |
0.6
|
top_p
|
float
|
Top-p for LLM |
0.95
|
max_tokens
|
int
|
Max tokens for LLM |
16000
|
max_workers
|
int
|
Max parallel workers for API calls |
DEFAULT_MAX_WORKERS
|
**kwargs
|
Additional configuration |
{}
|
Returns:
| Type | Description |
|---|---|
PipelineStage
|
Configured extractor stage |
Source code in stringsight/extractors/__init__.py
OpenAIExtractor¶
OpenAIExtractor
¶
Bases: LoggingMixin, TimingMixin, ErrorHandlingMixin, WandbMixin, PipelineStage
Extract behavioral properties using OpenAI models.
This stage takes conversations and extracts structured properties describing model behaviors, differences, and characteristics.
Source code in stringsight/extractors/openai.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
run(data, progress_callback=None, **kwargs)
async
¶
Run OpenAI extraction for all conversations.
Each conversation is formatted with prompt_builder and sent to the
OpenAI model in parallel using async. The raw LLM response is
stored inside a placeholder Property object (one per
conversation). Down-stream stages (LLMJsonParser) will parse these
raw strings into fully-formed properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PropertyDataset
|
PropertyDataset with conversations to extract from |
required |
progress_callback
|
Any
|
Optional callback(completed, total) for progress updates |
None
|
Source code in stringsight/extractors/openai.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
Clusterers¶
get_clusterer()¶
get_clusterer(method='hdbscan', min_cluster_size=None, embedding_model='sentence-transformers/all-MiniLM-L6-v2', assign_outliers=False, include_embeddings=False, cluster_positive=True, **kwargs)
¶
Factory function to get the appropriate clusterer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Clustering method ("hdbscan", "dummy") |
'hdbscan'
|
min_cluster_size
|
int | None
|
Minimum cluster size |
None
|
embedding_model
|
str
|
Embedding model to use |
'sentence-transformers/all-MiniLM-L6-v2'
|
assign_outliers
|
bool
|
Whether to assign outliers to nearest clusters |
False
|
include_embeddings
|
bool
|
Whether to include embeddings in output |
False
|
use_gpu
|
Enable GPU acceleration for embeddings and HDBSCAN. None (default) = auto-detect based on CUDA availability. |
required | |
cluster_positive
|
bool
|
If False and groupby_column is "behavior_type", skip clustering positive behaviors. Defaults to True. |
True
|
**kwargs
|
Additional configuration |
{}
|
Returns:
| Type | Description |
|---|---|
PipelineStage
|
Configured clusterer stage |
Source code in stringsight/clusterers/__init__.py
HDBSCANClusterer¶
HDBSCANClusterer
¶
Bases: BaseClusterer
HDBSCAN clustering stage.
This stage migrates the hdbscan_cluster_categories function from clustering/hierarchical_clustering.py into the pipeline architecture.
Source code in stringsight/clusterers/hdbscan.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
Metrics¶
get_metrics()¶
get_metrics(method, **kwargs)
¶
Factory function for metrics stages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
"side_by_side", "single_model", "functional", or "single_model_legacy" |
required |
**kwargs
|
Additional configuration for the metrics stage |
{}
|
Returns:
| Type | Description |
|---|---|
PipelineStage
|
Configured metrics stage |
Source code in stringsight/metrics/__init__.py
Utilities¶
Format Detection¶
detect_method(columns)
¶
Return the best-matching method based on available columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
List[str]
|
List of column names present in the dataset |
required |
Returns:
| Type | Description |
|---|---|
Optional[Method]
|
"single_model" | "side_by_side" if a set of required columns is satisfied, |
Optional[Method]
|
otherwise None. |
Source code in stringsight/formatters/traces.py
Validation¶
validate_required_columns(df, method)
¶
Return the list of missing required columns for the given method.
Empty list indicates the DataFrame satisfies the requirement.