Skip to main content
Glama

get_emsal_document_markdown

Retrieve Turkish legal precedent decision texts in Markdown format using the specified document ID for easy integration into LLM applications. Simplify legal document management with structured outputs.

Instructions

Get Emsal precedent decision text in Markdown format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes

Implementation Reference

  • Handler function implementing the core logic to retrieve an Emsal decision document by ID, fetch HTML from API, clean it, convert to Markdown, and return structured response.
    async def get_decision_document_as_markdown(self, id: str) -> EmsalDocumentMarkdown: """ Retrieves a specific Emsal decision by ID and returns its content as Markdown. Assumes Emsal /getDokuman endpoint returns JSON with HTML content in the 'data' field. """ document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={id}" source_url = f"{self.BASE_URL}{document_api_url}" logger.info(f"EmsalApiClient: Fetching Emsal document for Markdown (ID: {id}) from {source_url}") try: response = await self.http_client.get(document_api_url) response.raise_for_status() # Emsal /getDokuman returns JSON with HTML in 'data' field (confirmed by user example) response_json = response.json() html_content_from_api = response_json.get("data") if not isinstance(html_content_from_api, str) or not html_content_from_api.strip(): logger.warning(f"EmsalApiClient: Received empty or non-string HTML in 'data' field for Emsal ID {id}.") return EmsalDocumentMarkdown(id=id, markdown_content=None, source_url=source_url) markdown_content = self._clean_html_and_convert_to_markdown_emsal(html_content_from_api) return EmsalDocumentMarkdown( id=id, markdown_content=markdown_content, source_url=source_url ) except httpx.RequestError as e: logger.error(f"EmsalApiClient: HTTP error fetching Emsal document (ID: {id}): {e}") raise except ValueError as e: logger.error(f"EmsalApiClient: ValueError processing Emsal document response (ID: {id}): {e}") raise except Exception as e: logger.error(f"EmsalApiClient: General error processing Emsal document (ID: {id}): {e}") raise
  • Pydantic schema/model for the tool's output response containing the document ID, markdown content, and source URL.
    class EmsalDocumentMarkdown(BaseModel): """Model for an Emsal decision document, containing only Markdown content.""" id: str markdown_content: str = Field("", description="The decision content (Karar İçeriği) converted to Markdown.") source_url: HttpUrl
  • Supporting helper function that cleans escaped HTML content from the Emsal API response and converts it to Markdown format using MarkItDown library.
    def _clean_html_and_convert_to_markdown_emsal(self, html_content_from_api_data_field: str) -> Optional[str]: """ Cleans HTML (from Emsal API 'data' field containing HTML string) and converts it to Markdown using MarkItDown. This assumes Emsal /getDokuman response is JSON with HTML in "data" field, similar to Yargitay and the last Emsal /getDokuman example. """ if not html_content_from_api_data_field: return None # Basic HTML unescaping and fixing common escaped characters # Based on user's original fix_html_content in app/routers/emsal.py content = html.unescape(html_content_from_api_data_field) content = content.replace('\\"', '"') content = content.replace('\\r\\n', '\n') content = content.replace('\\n', '\n') content = content.replace('\\t', '\t') # The HTML string from "data" field starts with "<html><head>..." html_input_for_markdown = content markdown_text = None try: # Convert HTML string to bytes and create BytesIO stream html_bytes = html_input_for_markdown.encode('utf-8') html_stream = io.BytesIO(html_bytes) # Pass BytesIO stream to MarkItDown to avoid temp file creation md_converter = MarkItDown() conversion_result = md_converter.convert(html_stream) markdown_text = conversion_result.text_content logger.info("EmsalApiClient: HTML to Markdown conversion successful.") except Exception as e: logger.error(f"EmsalApiClient: Error during MarkItDown HTML to Markdown conversion for Emsal: {e}") return markdown_text

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/saidsurucu/yargi-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server