---
name: strip_markdown_codeblock
kind: function
lang: py
domain: core
version: "1.0.0"
purity: pure
signature: "def strip_markdown_codeblock(text: str) -> str"
description: "Remueve wrapping de code blocks markdown que modelos a veces anaden al responder JSON. Ej: ```json\\n{...}\\n``` → {...}"
tags: [llm, text, cleaning, markdown, codeblock, json]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: [re]
params:
  - name: text
    desc: "String posiblemente envuelto en markdown code block"
output: "String con los delimitadores ```json/``` removidos si estaban presentes"
tested: true
tests: ["JSON sin codeblock no cambia", "JSON con wrapper ```json es desenvuelto", "JSON con wrapper ``` solo es desenvuelto", "texto que no es JSON pasa sin cambio"]
test_file_path: "python/functions/core/strip_markdown_codeblock_test.py"
file_path: "python/functions/core/strip_markdown_codeblock.py"
---

## Ejemplo

```python
wrapped = '```json\n{"key": "value"}\n```'
result = strip_markdown_codeblock(wrapped)
# '{"key": "value"}'

plain = '{"key": "value"}'
result = strip_markdown_codeblock(plain)
# '{"key": "value"}'
```

## Notas

Funcion pura. Aplica cuatro pasos: strip inicial, remover prefijo ` ``` ` o ` ```json ` (case-insensitive), remover sufijo ` ``` `, strip final. Maneja tanto ` ```json ` como ` ``` ` generico. El flag IGNORECASE permite ` ```JSON ` o ` ```Json `.
