Input Contracts¶
Most users should pass supported data directly to Extractor. Integrations can
prepare input explicitly when they need to inspect normalized data or reuse one
document conversion across schema and extraction operations.
PreparedInput¶
Normalized extraction input and its owned resources.
InputProcessor creates this contract before planning or row processing.
Application code normally receives an ExtractionResult instead; this
type is primarily useful when calling FileReader directly.
Attributes:
| Name | Type | Description |
|---|---|---|
dataframe |
DataFrame
|
Source rows retained for planning, provenance, and optional DataFrame output. |
pdf_rows |
Dict[int, PdfRow]
|
Positional row mappings for multimodal PDF payloads. |
planning_sample |
Optional[str]
|
Text extracted once from a converted document for schema planning. Existing PDFs usually leave this unset and are attached directly to the planning request. |
owned_paths |
List[Path]
|
Temporary files that must be deleted after processing.
|
Source code in structx/core/input.py
closed
property
¶
Whether temporary resources owned by this input were released.
close()
¶
Release owned temporary resources. This operation is idempotent.
ensure_open()
¶
row_payload(position, row, target_columns)
¶
Build the text or PDF payload for one positional input row.
Source code in structx/core/input.py
PdfRow¶
A PDF payload associated with one source row.
Attributes:
| Name | Type | Description |
|---|---|---|
pdf_path |
Path
|
PDF sent to Instructor's multimodal input. |
source |
Path
|
Original user-supplied document path. For converted documents,
this differs from |
Source code in structx/core/input.py
Resource Ownership¶
FileReader.read_file() returns a PreparedInput. Existing PDFs are borrowed
and never deleted. Converted documents place generated PDFs in owned_paths.
One-shot Extractor methods clean those paths automatically. The public
preparation context managers keep prepared input open across schema and
extraction methods, then guarantee cleanup when the context exits:
from structx import Extractor
with extractor.prepare_input(data="agreement.docx") as prepared:
print(prepared.dataframe)
print(prepared.pdf_rows[0].pdf_path)
schema = extractor.get_schema(
data=prepared,
query="extract agreement terms",
)
result = extractor.extract(
data=prepared,
query="extract agreement terms",
model=schema,
)
Use async with extractor.prepare_input_async(...) when preparation may perform
blocking file parsing or document conversion. The prepared object can be
inspected for metering or status updates before any model-backed operation.
Lower-level callers can still use the idempotent PreparedInput.close() method
directly when a context manager is not suitable.
See Supported Formats for accepted public input types and document conversion behavior.