Database Models

Our RDBMS layer is very interesting: obviously it incorporates all of the traditional elements - all SQLAlchemy, but in order to be resiliant, we’ve a lot of JSON fields. These all have Pydantic models associated with them, so everything is deeply Pythonic.

../_images/erd.svg
class lbn.aidoc.models.Application

Bases: BaseModel

Structured JSON layout for a complete job application document set.

class CVProfile

Bases: BaseModel

keywords: List[str]
model_config = {'arbitrary_types_allowed': True, 'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

required: List[str]
sections: List[str]
subject: str | None
title: str
class LetterProfile

Bases: BaseModel

freetext: str
marketplace: List[str]
model_config = {'arbitrary_types_allowed': True, 'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

required: List[str]
sections: List[str]
title: str
__init__(**data: Any)

Surgical Constructor: Seamlessly intercepts input shapes, converting raw nested dictionaries into deep, dot-notation queryable sub-objects.

cv: Any
letter: Any
model_config = {'arbitrary_types_allowed': True, 'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

url: HttpUrl | None
class lbn.aidoc.models.Comment

Bases: SQLModel

__init__(**data)
as_str()
category: str
content: str
id: int | None
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property parent

Automatically extracts the database session from itself to find the parent model.

property parent_class
parent_id: int
parent_type: str
timestamp: datetime
class lbn.aidoc.models.Company

Bases: BaseEntity

__init__(**data)
analytics: Any
as_str()

Abstract string serialization method.

Must be explicitly overridden by every child model to pass system tests.

code: ANZSICCode | None
property employees: List[Person]

The genuine internal team: Bosses, Peers, Talent, etc.

geo: str | None
id
property is_agency: bool

Dynamically classifies recruitment status by reading taxonomy depth.

jobs: Mapped[List[Job]]
linkedin: str | None
location: str | None
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
property recruiters: List[Person]

The external agency partners linked to this company.

state: EntityStatus
stints: Mapped[List[EmploymentHistory]]
tier: CompanyTier | None
website: str | None
class lbn.aidoc.models.CompanyAlias

Bases: SQLModel

__init__(**data)
company_id: int
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
class lbn.aidoc.models.EmploymentHistory

Bases: SQLModel

The Ledger: Tracks who works (or worked) where.

__init__(**data)
archetype: Archetype
company: Mapped[Company]
company_id: int
end_date: datetime | None
id: int | None
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

person: Mapped[Person]
person_id: int
start_date: datetime | None
classmethod validate_styled_enums(v, info)

The ‘Inhale Handshake’: Forces Pydantic to use the StyledEnum constructor. This re-attaches the .style metadata lost during AI extraction.

class lbn.aidoc.models.Financials

Bases: SQLModel

Financial information, and state/processing of said information

__init__(**data)
analytics: Any
created_at: datetime
data: FinancialData
history: Mapped[List[History]]
id: int | None
initiative: Mapped[Initiative | None]
initiative_id: int
model_config = {'from_attributes': True, 'ignored_types': (<class 'sqlalchemy.ext.hybrid.hybrid_property'>,), 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
state: FinancialsStatus
updated_at: datetime
class lbn.aidoc.models.History

Bases: SQLModel

for state machine transition histories

__init__(**data)
id: int | None
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

new_status: str | None
note: str
old_status: str | None
parent_id: int
parent_type: str
timestamp: datetime
class lbn.aidoc.models.Initiative

Bases: SQLModel

A project/initiative - bucket of financials, people, tasks

__init__(**data)
analytics: Any
as_str()
champion_id: int | None
created_at: datetime
description: str | None
end_date: date | None
financials: Mapped[List[Financials]]
get_financial_record(name: str) Financials | None

Safely extracts a specific financial variant row matching the lookup name.

history: Mapped[List[History]]
id: int | None
initiative_type: InitiativeType
model_config = {'from_attributes': True, 'ignored_types': (<class 'sqlalchemy.ext.hybrid.hybrid_property'>,), 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

priority: Priority
start_date: date | None
state: InitiativeStatus
tasks: Mapped[List[Task]]
team: Mapped[List[Person]]
title: str
updated_at: datetime
classmethod validate_styled_enums(v, info)

The ‘Inhale Handshake’: Forces Pydantic to use the StyledEnum constructor. Re-attaches the color metadata attributes during extraction swaps.

class lbn.aidoc.models.Interview

Bases: BaseEntity

__init__(**data)
as_ical() str

Surgical Export: Generates a valid iCalendar byte string using the icalendar library.

as_str()

Abstract string serialization method.

Must be explicitly overridden by every child model to pass system tests.

attendee_ids: List[int]
property attendees: List[Person]

Surgical Lookahead: Direct session query to resolve the JSON list of IDs. Returns a list of Person objects matching the internal array registry.

history: Mapped[List[History]]
id
job: Mapped[Job | None]
job_id: int | None
location: str
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

predecessor: Mapped[Interview | None]
predecessor_id: int | None
predecessors() List[Interview]

Walks backwards up the chain of predecessor links. Returns a list of all prior interview objects, sorted chronologically.

scheduled_at: datetime
state: MeetingStatus
title: str
classmethod validate_styled_enums(v, info)

The ‘Inhale Handshake’: Forces Pydantic to use the StyledEnum constructor. This re-attaches the .style metadata lost during AI extraction.

class lbn.aidoc.models.Job

Bases: SQLModel

__init__(**data)
analytics: Any
annual_equivalent
applicants: int | None
application: Any
as_str()
closes: datetime | None
company: Mapped[Company | None]
company_id: int | None
description: str | None
expired_at: datetime | None
external_id: str | None
geo: str | None
history: Mapped[List[History]]
id: int | None
ingested
interviews: Mapped[List[Interview]]
job_style: JobStyle
job_type: JobType
keywords: List[str]
listed: datetime | None
location: str | None
model_config = {'from_attributes': True, 'ignored_types': (<class 'sqlalchemy.ext.hybrid.hybrid_property'>,), 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

priority: Priority
recruiter: Mapped[Person | None]
recruiter_id: int | None
salary_currency: str
salary_max: int | None
salary_min: int | None
salary_period: SalaryPeriod
score: float | None
source: Mapped[Source | None]
source_id: int | None
state: JobStatus
title: str
url: str | None
classmethod validate_styled_enums(v, info)

The ‘Inhale Handshake’: Forces Pydantic to use the StyledEnum constructor. This re-attaches the .style metadata lost during AI extraction.

version: int
class lbn.aidoc.models.Person

Bases: BaseEntity

The Master Address Book: Purely digital presence. Independence: No relationships or back-links defined here.

__init__(**data)
analytics: Any
apikey: str | None
as_str()

Abstract string serialization method.

Must be explicitly overridden by every child model to pass system tests.

check_password(raw_password: str) bool

Verify an incoming password attempt against the database hash.

colleagues(current_only: bool = True) List[Person]

Returns a list of all distinct people who work (or worked) at the same companies.

Executes a native SQL self-join on the ledger, completely bypassing in-memory loops.

email: str | None
property employer: Company | None

Returns the current Company from the latest stint.

first_name()
generate_apikey() str

Generate a secure, random API prefix string for headless CLI requests.

geo: str | None
id
jobtitle: str | None
last_name()
property latest_stint: EmploymentHistory | None

Returns the newest stint based on primary key ID fallback.

linkedin: str | None
location: str | None
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
password_hash: str | None
phone: str | None
set_password(raw_password: str) None

Hash a password securely using Python 3.13 standard libraries.

state: EntityStatus
stints: Mapped[List[EmploymentHistory]]
username: str | None
website: str | None
class lbn.aidoc.models.PersonAlias

Bases: SQLModel

__init__(**data)
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
person_id: int
class lbn.aidoc.models.Prompt

Bases: SQLModel

an LLM instruction, with well defined inputs and outputs

__init__(**data)
compile(**kwargs) List[Dict[str, str]]

The ‘Inhale’: Uses the input_model to resolve defaults and satisfy ‘required’ constraints before the slurp.

id: int | None
input_model() Type[BaseModel]

The ‘Inhale Contractor’: Dynamic validation block for input parameters. Recursively compiles a genuine Pydantic model contract straight from the stored input_schema JSON dictionary.

input_schema: Dict[str, Any]
inputs() Dict[str, List[str]]

Decomposes the input JSONSchema.

The ‘Linker’: turns dicts, etc into our pydantic output schema structure

model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
output_model() Type[BaseModel]

The ‘Inhale Contractor’: High-fidelity type mapping. Recursively compiles a genuine, deeply nested Pydantic model contract straight from the stored output_schema JSON dictionary.

output_schema: Dict[str, Any]
outputs() Dict[str, List[str]]

Decomposes the output JSONSchema.

provider: str | None
rst_files: Mapped[List[RSTFile]]
system_message: str
temperature: float
ttl: int
validate_schema_integrity() Prompt

Ensure every required field has a matching property definition.

weight: Weight
class lbn.aidoc.models.RSTFile

Bases: SQLModel

__init__(**data)
epigraph: str | None
epilog: str | None
id: int | None
is_active: bool
last_prompt_id: int | None
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
prolog: str | None
prompt: Mapped[Prompt | None]
raw_content: str | None
seealso: str | None
target_path: str
class lbn.aidoc.models.Source

Bases: SQLModel

__init__(**data)
domain: str
driver: str
extras: Dict[str, Any]
classmethod get_by_url(session: Session, url: str) Source

The Discovery Drill: Resolves Source by domain or falls back to ‘General’. PRINCIPAL: Guaranteed to return a Source object.

id: int | None
jobs: Mapped[List[Job]]
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
password: str | None
searches: Dict[str, Any]
url: str | None
username: str | None
class lbn.aidoc.models.Tag

Bases: SQLModel

Surgical Metadata: Dynamic labels with built-in style.

__init__(**data)
as_str()
id: int | None
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
style: str

Bases: SQLModel

The Glue: Polymorphic Many-to-Many link with a standard ID.

__init__(**data)
id: int | None
model_config = {'from_attributes': True, 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parent_id: int
parent_type: str
tag_id: int
class lbn.aidoc.models.Task

Bases: BaseEntity

TODO/Task List

__init__(**data)
as_todoist_payload() dict

Surgical Export: Generates a clean Todoist payload schema mapping. Translates our StyledEnum priorities into Todoist’s 1-4 numeric envelope.

blocked_by_id: int | None
blocker_reason: str | None
created_at: datetime
description: str | None
due_date: datetime | None
history: Mapped[List[History]]
id
is_blocked
model_config = {'from_attributes': True, 'ignored_types': (<class 'sqlalchemy.ext.hybrid.hybrid_property'>,), 'read_from_attributes': True, 'read_with_orm_mode': True, 'registry': PydanticUndefined, 'table': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parent_id: int
parent_type: str
priority: Priority
state: TaskStatus
title: str
updated_at: datetime
classmethod validate_styled_enums(v, info)

The ‘Inhale Handshake’: Forces Pydantic to use the StyledEnum constructor. This re-attaches the .style metadata lost during database serialization.

lbn.aidoc.models.find_company(session: Session, search_name: str)
lbn.aidoc.models.find_person(session: Session, name: str = None, email: str = None)

The ‘Identity Drill’: Resolves Person via name/email or Name Alias. Surgically strikes only existing hardware columns. No redundant imports.

lbn.aidoc.models.get_comments_for(session, item)

Retrieves all narrative notes for the parent item.

lbn.aidoc.models.get_tags_for(session, item) List[Tag]

Surgical Retrieval: Reaches into the TagLink silo for any arbitrary model.

lbn.aidoc.models.make_comment(item, content, category='note', timestamp=None)

Surgically injects a narrative comment against any hunting stakeholder model. Forces parent types to match get_comments_for extraction queries.