[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-273353-105":59,"doc-detail-273353-en":130},{"code":4,"msg":5,"data":6},0,"success",[7,13,18,23,28,33,38,43,48,51,55],{"id":8,"doc_module":4,"doc_module_name":9,"category_name":10,"show_sort_weight":11,"slug":12},1,"Document","Story & Novel",90,"story-novel",{"id":14,"doc_module":4,"doc_module_name":9,"category_name":15,"show_sort_weight":16,"slug":17},2,"Literature",80,"literature",{"id":19,"doc_module":4,"doc_module_name":9,"category_name":20,"show_sort_weight":21,"slug":22},4,"Exam",70,"exam",{"id":24,"doc_module":4,"doc_module_name":9,"category_name":25,"show_sort_weight":26,"slug":27},5,"Comic",60,"comic",{"id":29,"doc_module":4,"doc_module_name":9,"category_name":30,"show_sort_weight":31,"slug":32},6,"Technology",50,"technology",{"id":34,"doc_module":4,"doc_module_name":9,"category_name":35,"show_sort_weight":36,"slug":37},7,"Healthcare",40,"healthcare",{"id":39,"doc_module":4,"doc_module_name":9,"category_name":40,"show_sort_weight":41,"slug":42},8,"Research & Report",30,"research-report",{"id":44,"doc_module":4,"doc_module_name":9,"category_name":45,"show_sort_weight":46,"slug":47},9,"Religion & Spirituality",20,"religion-spirituality",{"id":46,"doc_module":4,"doc_module_name":9,"category_name":49,"show_sort_weight":46,"slug":50},"World Cup","world-cup",{"id":52,"doc_module":4,"doc_module_name":9,"category_name":53,"show_sort_weight":52,"slug":54},10,"Lifestyle","lifestyle",{"id":56,"doc_module":4,"doc_module_name":9,"category_name":57,"show_sort_weight":24,"slug":58},19,"General","general",{"code":4,"msg":60,"data":61},"ok",{"site_id":62,"language":63,"slug":64,"title":65,"keywords":66,"description":67,"schema_data":68,"social_meta":123,"head_meta":125,"extra_data":127,"updated_unix":129},105,"en","library-hallucinations-in-llm-generated-code-a-risk-analysis-grounded-in-developer-queries","Library Hallucinations in LLM-Generated Code - A Risk Analysis Grounded in Developer Queries","","Large language models (LLMs) increasingly generate code, but they still hallucinate—especially by inventing nonexistent libraries. These errors can mislead developers, fail builds, and enable supply-chain threats such as slopsquatting. Limited prior work explains how such library hallucinations arise under realistic developer prompting. This study systematically tests how prompt variations drive both library name and library member hallucinations across seven LLMs. Results reveal sharp vulnerability to misspellings and time-based prompts, plus acceptance of fabricated library names. A benchmark, LIBHALLUBENCH, supports reproducible evaluation and mitigation.",{"@graph":69,"@context":122},[70,84,105],{"@type":71,"itemListElement":72},"BreadcrumbList",[73,77,79,82],{"item":74,"name":75,"@type":76,"position":8},"https://docshare.wps.com","Home","ListItem",{"item":78,"name":9,"@type":76,"position":14},"https://docshare.wps.com/document/",{"item":80,"name":40,"@type":76,"position":81},"https://docshare.wps.com/document/research-report/",3,{"item":83,"name":65,"@type":76,"position":19},"https://docshare.wps.com/document/library-hallucinations-in-llm-generated-code-a-risk-analysis-grounded-in-developer-queries/273353/",{"url":83,"name":65,"@type":85,"image":86,"author":91,"headline":65,"publisher":94,"fileFormat":97,"inLanguage":63,"description":67,"dateModified":98,"datePublished":99,"encodingFormat":97,"isAccessibleForFree":100,"interactionStatistic":101},"DigitalDocument",{"url":87,"@type":88,"width":89,"height":90},"https://docshare.wps.com/thumbnails/library-hallucinations-in-llm-generated-code-a-risk-analysis-grounded-in-developer-queries/273353.png","ImageObject",300,407,{"name":92,"@type":93},"Logic","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-10-29","2026-09-15",true,{"@type":102,"interactionType":103,"userInteractionCount":39},"InteractionCounter",{"@type":104},"ViewAction",{"@type":106,"mainEntity":107},"FAQPage",[108,114,118],{"name":109,"@type":110,"acceptedAnswer":111},"What problem does the study address about LLM-generated code?","Question",{"text":112,"@type":113},"The study addresses library hallucinations in LLM-generated code, where models invent nonexistent libraries or invalid members. It focuses on how these failures arise under realistic developer prompt conditions.","Answer",{"name":115,"@type":110,"acceptedAnswer":116},"How do prompt variations affect library hallucination rates?",{"text":117,"@type":113},"Across seven LLMs, the study finds that one-character misspellings can trigger hallucinations in up to 26% of tasks, fabricated library names can be accepted in up to 99%, and time-based prompts can induce hallucinations in up to 85%.",{"name":119,"@type":110,"acceptedAnswer":120},"What is LIBHALLUBENCH and why is it introduced?",{"text":121,"@type":113},"LIBHALLUBENCH is a benchmark built from the highest-risk prompts identified in the study. It enables systematic, reproducible evaluation of library hallucinations under controlled conditions.","https://schema.org",{"og:url":83,"og:type":124,"og:title":65,"og:site_name":95,"og:description":67},"article",{"robots":126,"canonical":83},"index,follow",{"doc_id":128,"site_id":62},273353,1790346333,{"code":4,"msg":5,"data":131},{"doc_id":128,"user_id":132,"nickname":92,"user_avatar":133,"doc_module":4,"category_id":39,"category_name":40,"doc_title":65,"doc_description":67,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":39,"is_deleted":4,"is_public":8,"is_downloadable":8,"audit_status":8,"page_count":139,"language":140,"language_code":63,"site_id":62,"html_lang":63,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":67,"update_tm":144,"read_time":145,"preview_page_count":4},1099513958762,"https://ap-avatar.wpscdn.com/avatar/1000023916a998db790?x-image-process=image/resize,m_fixed,w_180,h_180&k=1784791008015729253","Library Hallucinations in LLM-Generated Code: A Risk Analysis Grounded in Developer Queries  \nLukas Twist1 Mark Harman2  \nHelen Yannakoudakis1 Jie M. Zhang1  \n1 King’s College London, London, UK  \n2University College London, London, UK  \narXiv : 2509 .22202v4 [cs .SE] 2 1 Aug 2026  \nAbstract  \nLarge language models (LLMs) now play a central role in code generation, yet they continue to hallucinate, frequently inventing nonexistent libraries. Such library hallucinations are not just benign errors: they can mislead developers, break builds, and expose systems to supply chain threats such as slopsquatting. Despite growing awareness of these risks, there is limited understanding of how library hallucinations manifest under realistic usage conditions. To fill this gap, we present the first systematic study of how user-level prompt variations influence library hallucinations in LLM-generated code. Across seven diverse LLMs, we analyse library name hallucinations (invalid imports) and library member hallucinations (invalid calls from valid libraries), examining the effects of realistic developer language and controlled user mistakes, including misspellings and fabricated libraries or members. Our findings expose systemic vulnerabilities: one-character misspellings trigger hallucinations in up to 26% of tasks; fabricated library names are accepted in up to 99%; and time-based prompts induce hallucinations in up to 85% . Grounded in the highest-risk prompts identified in our study, we introduce LIBHALLUBENCH, a benchmark that enables a systematic and reproducible evaluation of these library hallucinations. Our findings underscore the fragility of LLMs to natural prompt variation and highlight the urgent need for safeguards against library-related hallucinations and their downstream risks.  \n1 Introduction  \nLarge language models (LLMs) have rapidly become integral to modern software development, translating natural language (NL) prompts into executable code with remarkable accuracy and speed (Jiang et al., 2024a) . Their high merge rates in industry (Gao and Research, 2024 ; Novet and  \nVanian, 2025) indicate that LLM-generated code is no longer experimental, but increasingly deployed in real-world systems. However, the reliability of this code remains a critical concern. A particularly serious failure mode is code hallucinations, in which LLMs fabricate elements of the generated code (Zhang et al., 2024 ; Lee et al., 2025) . Unlike typical bugs, hallucinations are often generated confidently as syntactically valid, plausible code; they may not trigger immediate errors (e.g. when they conflict with task requirements rather than execution), and can mislead developers about the validity of the generated output.  \nThe problem is particularly acute for external libraries, which underpin contemporary software engineering and are routinely used to accelerate development (Larios Vargas et al., 2020) . Despite the existence of verifiable ground truth in documentation and package registries, LLMs still frequently exhibit library-related hallucinations when generating code (Spracklen et al., 2025) . Such failures can bypass dependency validation and lead developers to adopt invalid, deprecated, or malicious packages, introducing practical reliability and security risks (Krishna et al., 2025 ; Wang et al., 2025a) . Furthermore, the emergence of “slopsquatting” – where a frequently hallucinated library is created by an attacker – poses another significant threat, one specific to library hallucinations (Park, 2025) .  \nExisting studies on library hallucinations largely define the problem at an aggregate level, without systematically analysing what triggers them (Krishna et al., 2025 ; Spracklen et al., 2025) . As a result, we lack a fine-grained understanding of how prompt variations influence hallucination rates, and there is no standardised benchmark for measuring these effects under controlled conditions. Understanding how LLMs react to realisti","cbCaie9GSw7nvbHA","https://ap.wps.com/l/cbCaie9GSw7nvbHA","pdf",513302,28,"English","# Introduction\n## Hallucinations and their impact on code generation\n## Library-related hallucinations and related security threats\n## Gap in prior work\n## Study approach and evaluation pipeline\n## Experimental design and prompt conditions","[{\"question\":\"What problem does the study address about LLM-generated code?\",\"answer\":\"The study addresses library hallucinations in LLM-generated code, where models invent nonexistent libraries or invalid members. It focuses on how these failures arise under realistic developer prompt conditions.\"},{\"question\":\"How do prompt variations affect library hallucination rates?\",\"answer\":\"Across seven LLMs, the study finds that one-character misspellings can trigger hallucinations in up to 26% of tasks, fabricated library names can be accepted in up to 99%, and time-based prompts can induce hallucinations in up to 85%.\"},{\"question\":\"What is LIBHALLUBENCH and why is it introduced?\",\"answer\":\"LIBHALLUBENCH is a benchmark built from the highest-risk prompts identified in the study. It enables systematic, reproducible evaluation of library hallucinations under controlled conditions.\"}]","Library Hallucinations in LLM-Generated Code - A Risk Analysis Grounded in Developer Queries | PDF",1789471019,71]