get_sayistay_document_unified
Retrieve full-text audit decisions from Sayıştay in clean Markdown format using decision ID and type for legal research and analysis.
Instructions
Use this when retrieving full text of a Sayıştay audit decision. Returns clean Markdown format.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| decision_id | Yes | Decision ID from search_sayistay_unified results | |
| decision_type | Yes | Decision type: genel_kurul, temyiz_kurulu, or daire |
Implementation Reference
- Handler function that provides unified access to Sayistay decision documents across all decision types (genel_kurul, temyiz_kurulu, daire) by calling the underlying client and returning structured Markdown output.async def get_document_unified(self, decision_id: str, decision_type: str) -> SayistayUnifiedDocumentMarkdown: """Unified document retrieval for all Sayıştay decision types.""" # Use existing client method (decision_type is already a string) result = await self.client.get_document_as_markdown(decision_id, decision_type) return SayistayUnifiedDocumentMarkdown( decision_type=decision_type, decision_id=result.decision_id, source_url=result.source_url, document_data=result.model_dump(), markdown_content=result.markdown_content, error_message=result.error_message )
- Core helper method in SayistayApiClient that performs the actual HTTP request to fetch decision document HTML, converts it to Markdown using MarkItDown, and handles session management, CSRF, and errors.async def get_document_as_markdown(self, decision_id: str, decision_type: str) -> SayistayDocumentMarkdown: """ Retrieve full text of a Sayıştay decision and convert to Markdown. Args: decision_id: Unique decision identifier decision_type: Type of decision ('genel_kurul', 'temyiz_kurulu', 'daire') Returns: SayistayDocumentMarkdown with converted content """ logger.info(f"Retrieving document for {decision_type} decision ID: {decision_id}") # Validate decision_id if not decision_id or not decision_id.strip(): return SayistayDocumentMarkdown( decision_id=decision_id, decision_type=decision_type, source_url="", markdown_content=None, error_message="Decision ID cannot be empty" ) # Map decision type to URL path url_path_mapping = { 'genel_kurul': 'KararlarGenelKurul', 'temyiz_kurulu': 'KararlarTemyiz', 'daire': 'KararlarDaire' } if decision_type not in url_path_mapping: return SayistayDocumentMarkdown( decision_id=decision_id, decision_type=decision_type, source_url="", markdown_content=None, error_message=f"Invalid decision type: {decision_type}. Must be one of: {list(url_path_mapping.keys())}" ) # Build document URL url_path = url_path_mapping[decision_type] document_url = f"{self.BASE_URL}/{url_path}/Detay/{decision_id}/" try: # Make HTTP GET request to document URL headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "same-origin" } # Include session cookies if available if self.session_cookies: cookie_header = "; ".join([f"{k}={v}" for k, v in self.session_cookies.items()]) headers["Cookie"] = cookie_header response = await self.http_client.get(document_url, headers=headers) response.raise_for_status() html_content = response.text if not html_content or not html_content.strip(): logger.warning(f"Received empty HTML content from {document_url}") return SayistayDocumentMarkdown( decision_id=decision_id, decision_type=decision_type, source_url=document_url, markdown_content=None, error_message="Document content is empty" ) # Convert HTML to Markdown using existing method markdown_content = self._convert_html_to_markdown(html_content) if markdown_content and "Error converting HTML content" not in markdown_content: logger.info(f"Successfully retrieved and converted document {decision_id} to Markdown") return SayistayDocumentMarkdown( decision_id=decision_id, decision_type=decision_type, source_url=document_url, markdown_content=markdown_content, retrieval_date=None # Could add datetime.now().isoformat() if needed ) else: return SayistayDocumentMarkdown( decision_id=decision_id, decision_type=decision_type, source_url=document_url, markdown_content=None, error_message=f"Failed to convert HTML to Markdown: {markdown_content}" ) except httpx.HTTPStatusError as e: error_msg = f"HTTP error {e.response.status_code} when fetching document: {e}" logger.error(f"HTTP error fetching document {decision_id}: {error_msg}") return SayistayDocumentMarkdown( decision_id=decision_id, decision_type=decision_type, source_url=document_url, markdown_content=None, error_message=error_msg ) except httpx.RequestError as e: error_msg = f"Network error when fetching document: {e}" logger.error(f"Network error fetching document {decision_id}: {error_msg}") return SayistayDocumentMarkdown( decision_id=decision_id, decision_type=decision_type, source_url=document_url, markdown_content=None, error_message=error_msg ) except Exception as e: error_msg = f"Unexpected error when fetching document: {e}" logger.error(f"Unexpected error fetching document {decision_id}: {error_msg}") return SayistayDocumentMarkdown( decision_id=decision_id, decision_type=decision_type, source_url=document_url, markdown_content=None, error_message=error_msg )
- Pydantic schema for the output of the get_document_unified tool, defining the structure including decision metadata, source URL, Markdown content, and error handling.class SayistayUnifiedDocumentMarkdown(BaseModel): """Unified document model for all Sayıştay decision types.""" decision_type: Literal["genel_kurul", "temyiz_kurulu", "daire"] = Field(..., description="Type of document") decision_id: str = Field(..., description="Decision ID") source_url: str = Field(..., description="Source URL of the document") document_data: Dict[str, Any] = Field(default_factory=dict, description="Document content and metadata") markdown_content: Optional[str] = Field(None, description="Markdown content") error_message: Optional[str] = Field(None, description="Error message if retrieval failed")