"""Prompt template for code validation AI chain."""
from __future__ import annotations
from langchain_core.output_parsers import PydanticOutputParser
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from claim_validator.chains.output_schemas.code_validation import CodeValidationOutput

_parser = PydanticOutputParser(pydantic_object=CodeValidationOutput)

CODE_VALIDATION_PROMPT = ChatPromptTemplate.from_messages([
    ("system",
     "You are a medical coding auditor. Analyze the diagnosis-procedure combinations "
     "in this claim for clinical plausibility.\n\n"
     "Rules:\n- Flag gender-specific procedures billed for wrong gender\n"
     "- Flag age-inappropriate procedures\n"
     "- Flag diagnosis codes that do not clinically support the procedure\n"
     "- Only flag clear implausibilities, not borderline cases\n\n"
     "{format_instructions}"),
    MessagesPlaceholder("history", optional=True),
    ("human", "{claim_data}"),
]).partial(format_instructions=_parser.get_format_instructions())
