create_feature
Create feature definitions to link labels, scores, or derived assets to domain objects, enabling type-safe ML data engineering.
Instructions
Create a new feature definition to associate metadata with domain objects.
Features enable ML data engineering by linking labels, scores, or derived assets to domain objects. The feature definition specifies what types of values are valid.
What this creates:
A new association table in the domain schema to store feature values
A dynamically generated Pydantic model class for creating validated feature instances
The Pydantic model class (accessible via feature_record_class() in Python) provides
type-safe construction of feature records with automatic validation against the
feature's definition.
Feature types:
Term-based: Values come from controlled vocabularies (e.g., diagnosis labels)
Asset-based: Values reference asset files (e.g., segmentation masks)
Mixed: Can reference both terms and assets
The feature automatically tracks which Execution produced each value for provenance.
Args: table_name: Table to attach the feature to (e.g., "Image", "Subject"). feature_name: Unique name for the feature (e.g., "Diagnosis", "Quality_Score"). comment: Description of what this feature represents. terms: Vocabulary table names whose terms can be values (e.g., ["Diagnosis_Type"]). assets: Asset table names that can be referenced (e.g., ["Segmentation_Mask"]). metadata: Additional columns or table references to include in the feature. Each item can be: - A string: Treated as a table name (adds a foreign key reference) - A dict: Column definition with at minimum "name" and "type" keys. The "type" value should be a dict like {"typename": "float4"}. Valid type names: text, int2, int4, int8, float4, float8, boolean, date, timestamp, timestamptz, json, jsonb. Optional keys: "nullok" (bool), "default", "comment".
Returns: JSON with status, feature_name, target_table.
Examples: # Simple term-based feature create_feature("Image", "Diagnosis", "Clinical diagnosis label", terms=["Diagnosis_Type"])
# Feature with a confidence score column
create_feature("Image", "Diagnosis", "Diagnosis with confidence",
terms=["Diagnosis_Type"],
metadata=[{"name": "confidence", "type": {"typename": "float4"}}])
# Feature referencing another table
create_feature("Image", "Review", "Review annotations",
terms=["Review_Status"],
metadata=["Reviewer"])
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| terms | No | ||
| assets | No | ||
| comment | No | ||
| metadata | No | ||
| table_name | Yes | ||
| feature_name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |