The anonymization of medical texts in Spanish is essential for safeguarding patient privacy and ensuring compliance with regulations such as the General Data Protection Regulation (GDPR). This study explores the application of Large Language Models (LLMs) to automate the de-identification of Protected Health Information (PHI) in clinical texts, using foundational models like Gemma-2 (9B and 2B) and Llama (3.1 8B and 3.2 3B). Two benchmark datasets, DisMed and MEDDOCAN, were used to evaluate performance, providing a diverse range of clinical narratives and structured records for testing the models' efficacy. The methodology employed few-shot learning to guide LLMs in recognizing and tagging PHI entities such as names, dates, locations, and numerical identifiers. Custom evaluation metrics, including overlap-based and similarity-based methods, were introduced to address the limitations of traditional exact-match metrics, enabling a more nuanced analysis of model outputs. Post-processing steps ensured accurate and non-overlapping entity annotations to refine the anonymization process. Results showed that larger models, such as Gemma-2 9B and Llama 3.1 8B, achieved high F1 scores across most PHI categories, with particularly strong performance in standardized entities like addresses and locations. However, challenges remained in identifying diverse formats of dates and numerical data. The models demonstrated greater adaptability compared to traditional approaches, but occasional generation of hallucinated entities highlighted areas for improvement. Dataset quality and diversity significantly influenced performance, underscoring the importance of robust training data. The study concludes that LLMs are effective in automating the de-identification of Spanish medical texts, meeting the objective of providing a reliable and efficient anonymization solution. While computational costs and variability in certain outputs pose challenges, this work lays a strong foundation for future research to enhance the scalability and precision of these systems, facilitating secure data sharing and compliance in medical research.