Includes: API (Express/TypeScript), Astro site, Python workers, document generators, FCC compliance tools, Canada CRTC formation, Ansible infrastructure, and deployment scripts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
105 lines
4.2 KiB
Python
105 lines
4.2 KiB
Python
"""Contractor Classification Review handler (LLM-based).
|
|
|
|
Analyzes independent contractor vs. employee classification under IRS, DOL,
|
|
and applicable state tests (ABC test, economic reality test, etc.).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from .base_handler import BaseServiceHandler
|
|
|
|
SERVICE_SYSTEM_PROMPT = """You are a compliance analyst at Performance West Inc.
|
|
generating an Independent Contractor Classification Review report.
|
|
|
|
RULES:
|
|
- Write in professional, clear business English
|
|
- Reference the IRS 20-factor test, DOL economic reality test, and relevant state ABC tests
|
|
- Never provide legal advice — use "we recommend" not "you must"
|
|
- For each worker reviewed: classification determination, supporting factors, risk assessment
|
|
- Note state-specific tests (CA AB5, MA ABC test, NJ ABC test, etc.)
|
|
- Structure findings with clear headings and risk ratings (Low/Medium/High/Critical)
|
|
"""
|
|
|
|
SECTIONS = [
|
|
{
|
|
"name": "executive_summary",
|
|
"prompt": (
|
|
"Write a 200-word executive summary of the contractor classification "
|
|
"review. Include scope, number of contractor relationships reviewed, "
|
|
"overall risk posture, and key recommendations."
|
|
),
|
|
},
|
|
{
|
|
"name": "legal_framework",
|
|
"prompt": (
|
|
"Summarize the applicable legal framework for worker classification. "
|
|
"Cover: IRS common-law test (behavioral control, financial control, "
|
|
"relationship type), DOL economic reality test, state-specific tests "
|
|
"applicable to this client, and recent enforcement trends."
|
|
),
|
|
},
|
|
{
|
|
"name": "classification_analysis",
|
|
"prompt": (
|
|
"Analyze each contractor relationship against the applicable tests. "
|
|
"For each: describe the engagement, apply the IRS factors, apply the "
|
|
"DOL economic reality test, apply any relevant state test, and give "
|
|
"a risk rating. Flag any relationships that may warrant reclassification."
|
|
),
|
|
},
|
|
{
|
|
"name": "agreement_review",
|
|
"prompt": (
|
|
"Review the contractor agreements for protective language. Assess: "
|
|
"scope of work specificity, control provisions, termination clauses, "
|
|
"IP ownership, non-compete/non-solicitation, indemnification, and "
|
|
"whether the agreements align with actual practice."
|
|
),
|
|
},
|
|
{
|
|
"name": "remediation_plan",
|
|
"prompt": (
|
|
"Provide a prioritized remediation plan. For each finding: reference, "
|
|
"risk level, recommended action, responsible party, timeline. Include "
|
|
"recommendations for reclassification processes, back-tax exposure "
|
|
"mitigation (e.g., Section 530 relief, VCSP), and agreement revisions."
|
|
),
|
|
},
|
|
]
|
|
|
|
|
|
class ContractorReviewHandler(BaseServiceHandler):
|
|
SERVICE_SLUG = "contractor-classification"
|
|
SERVICE_NAME = "Contractor Classification Review"
|
|
TEMPLATE_NAME = "contractor_review_template.docx"
|
|
REQUIRES_LLM = True
|
|
|
|
async def process(self, order_data: dict) -> list[str]:
|
|
work_dir = self._make_work_dir()
|
|
order_number = order_data["name"]
|
|
context = self._extract_order_context(order_data)
|
|
|
|
template_path = self._get_template_path()
|
|
docx_filename = self._output_filename(order_number, "docx")
|
|
docx_path = os.path.join(work_dir, docx_filename)
|
|
|
|
variables = {
|
|
"order_number": order_number,
|
|
"customer_name": order_data.get("customer_name", ""),
|
|
"date": __import__("datetime").datetime.now().strftime("%B %d, %Y"),
|
|
"service_name": self.SERVICE_NAME,
|
|
"company_size": order_data.get("custom_company_size", "N/A"),
|
|
"industry": order_data.get("custom_industry", "N/A"),
|
|
"state": order_data.get("custom_state", "N/A"),
|
|
}
|
|
self._fill_template(template_path, variables, docx_path)
|
|
|
|
sections = await self._generate_sections(
|
|
SERVICE_SYSTEM_PROMPT, SECTIONS, context
|
|
)
|
|
self._add_sections_to_doc(docx_path, sections)
|
|
|
|
pdf_path = self._convert_to_pdf(docx_path)
|
|
return [docx_path, pdf_path]
|