Models¶
These are the core models used in structx
for data extraction and results.
ExtractionResult¶
Container for extraction results.
Attributes:
Name | Type | Description |
---|---|---|
data |
Union[DataFrame, List[T]]
|
Extracted data (DataFrame or list of model instances) |
failed |
DataFrame
|
DataFrame with failed extractions |
model |
Type[T]
|
Generated or provided model class |
usage |
Optional[ExtractorUsage]
|
Token usage information across all extraction steps |
Source code in structx/core/models.py
failure_count
property
¶
Number of failed extractions
success_count
property
¶
Number of successful extractions
success_rate
property
¶
Success rate as a percentage
get_token_usage(detailed=False)
¶
Get structured token usage information.
Provides a detailed breakdown of token usage across all steps of the extraction process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detailed
|
bool
|
If True, includes detailed breakdown of each extraction step (useful for multi-document extraction) |
False
|
Returns:
Type | Description |
---|---|
Optional[UsageSummary]
|
UsageSummary object with token usage information, or None if usage tracking |
Optional[UsageSummary]
|
isn't available |
Example
```python result = extractor.extract(data, query) usage = result.get_token_usage() print(f"Total tokens: {usage.total_tokens}")
Access step-specific usage¶
for step in usage.steps: print(f"{step.name}: {step.tokens} tokens")
Source code in structx/core/models.py
Other Models¶
ExtractionGuide
¶
Guide for structured extraction
Source code in structx/core/models.py
ExtractionRequest
¶
Request for model generation
Source code in structx/core/models.py
ExtractionResult
dataclass
¶
Container for extraction results.
Attributes:
Name | Type | Description |
---|---|---|
data |
Union[DataFrame, List[T]]
|
Extracted data (DataFrame or list of model instances) |
failed |
DataFrame
|
DataFrame with failed extractions |
model |
Type[T]
|
Generated or provided model class |
usage |
Optional[ExtractorUsage]
|
Token usage information across all extraction steps |
Source code in structx/core/models.py
failure_count
property
¶
Number of failed extractions
success_count
property
¶
Number of successful extractions
success_rate
property
¶
Success rate as a percentage
get_token_usage(detailed=False)
¶
Get structured token usage information.
Provides a detailed breakdown of token usage across all steps of the extraction process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detailed
|
bool
|
If True, includes detailed breakdown of each extraction step (useful for multi-document extraction) |
False
|
Returns:
Type | Description |
---|---|
Optional[UsageSummary]
|
UsageSummary object with token usage information, or None if usage tracking |
Optional[UsageSummary]
|
isn't available |
Example
```python result = extractor.extract(data, query) usage = result.get_token_usage() print(f"Total tokens: {usage.total_tokens}")
Access step-specific usage¶
for step in usage.steps: print(f"{step.name}: {step.tokens} tokens")
Source code in structx/core/models.py
ModelField
¶
Definition of a field in the extraction model
Source code in structx/core/models.py
QueryAnalysis
¶
QueryRefinement
¶
Refined query with structural information