Prompt Engineering Best Practices for Code Generation Tools
DOI:
https://doi.org/10.63282/3050-9246.IJETCSIT-V5I1P108Keywords:
Prompt Engineering, Large Language Models, Code Generation, Natural Language Processing, Few-shot LearningAbstract
Automated code generation has taken a major leap with the emergence of the Large Language Models (LLMs), including the Codex of OpenAI, Google AlphaCode and Code LLaMA of Meta. Nonetheless, in a bid to do justice to the abilities of such models, prompt engineering has become an important methodology. Prompt engineering is the art of carefully framing input queries or commands to achieve maximum quality and reliability of output. The intention of a user and machine interpretation can be met through well-constructed prompts in the process of code generation, resulting in efficient and safe source code with syntactic correctness. In this paper, best practices in the specific case of prompt engineering on code generation tools will be discussed. We talk about the fundamentals of efficient prompts, the method of few-shot learning, the zero-shot learning method, chain-of-thought prompting, and contrastive examples. In addition, we compare timely templates, tokenization optimization options, and role-based system messages. Through controlled experiments on an array of LLM platforms before October 2024, we will present some empirical evidence, pointing out the role of prompt structure in terms of the error rate, code completeness, and code quality one should expect. Prompt variants, evaluation metrics (e.g., functional correctness, cyclomatic complexity), and other pitfalls (e.g. prompt leakage, hallucination) are described in tables and figures in this study. We propose a systematic approach to building, then iterating and testing prompts that can be used to address code generation activities using over a dozen examples, such as the synthesis of algorithms, API call generation, and debugging. Findings indicate that an increase of up to 45 percent improvement in code precision and a 60 percent decrease in runtime bugs occur with the best-practice prompt structures. The results of our investigations proposed guidelines and taxonomy to support researchers in their lofty goals and developers and educators in their ambitions to exploit timely engineering in the construction of production-quality coding
Downloads
References
[1] Chen, M., Tworek, J., Jun, H., Yuan, Q., Pinto, H. P. D. O., Kaplan, J., ... & Zaremba, W. (2021). Evaluating large language models trained on code. arXiv preprint arXiv:2107.03374.
[2] Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I. (2017). Attention is all you need. Advances in neural information processing systems, 30.
[3] Allamanis, M., Barr, E. T., Devanbu, P., & Sutton, C. (2018). A survey of machine learning for big code and naturalness. ACM Computing Surveys (CSUR), 51(4), 1-37.
[4] Ahmad, W. U., Chakraborty, S., Ray, B., & Chang, K. W. (2021). Unified pre-training for program understanding and generation. arXiv preprint arXiv:2103.06333.
[5] Austin, J., Odena, A., Nye, M., Bosma, M., Michalewski, H., Dohan, D., ... & Sutton, C. (2021). Program synthesis with large language models. arXiv preprint arXiv:2108.07732.
[6] Nijkamp, E., Pang, B., Hayashi, H., Tu, L., Wang, H., Zhou, Y., ... & Xiong, C. (2022). Codegen: An open, large language model for code with multi-turn program synthesis. arXiv preprint arXiv:2203.13474.
[7] Wei, J., Wang, X., Schuurmans, D., Bosma, M., Xia, F., Chi, E., ... & Zhou, D. (2022). Chain-of-thought prompting elicits reasoning in large language models. Advances in neural information processing systems, 35, 24824-24837.
[8] Feng, Z., Guo, D., Tang, D., Duan, N., Feng, X., Gong, M., ... & Zhou, M. (2020). Codebert: A pre-trained model for programming and natural languages. arXiv preprint arXiv:2002.08155.
[9] Brown, T., Mann, B., Ryder, N., Subbiah, M., Kaplan, J. D., Dhariwal, P., ... & Amodei, D. (2020). Language models are few-shot learners. Advances in neural information processing systems, 33, 1877-1901.
[10] Huang et al. (2020) – Studied the effects of prompt personalization on the quality of code generated by language models.
[11] Chen, B., Zhang, Z., Langrené, N., & Zhu, S. (2023). Unleashing the potential of prompt engineering in large language models: A comprehensive review. arXiv preprint arXiv:2310.14735.
[12] Nye, M., Andreassen, J. A., Gur Ari, G., Michalewski, H., & Austin, J. (2021). Show Your Work: Scratchpads for Intermediate Computation with Language Models. Introduction of inserting intermediate “scratchpad” reasoning steps to improve task performance.
[13] Belzner, L., Gabor, T., & Wirsing, M. (2023, October). Large language model assisted software engineering: prospects, challenges, and a case study. In International Conference on Bridging the Gap between AI and Reality (pp. 355-374). Cham: Springer Nature Switzerland.
[14] Zhang, Q., Fang, C., Xie, Y., Zhang, Y., Yang, Y., Sun, W., ... & Chen, Z. (2023). A survey on large language models for software engineering. arXiv preprint arXiv:2312.15223.
[15] Muktadir, G. M. (2023). A brief history of prompt: Leveraging language models. (through advanced prompting). arXiv preprint arXiv:2310.04438.
[16] Liu, P., Yuan, W., Fu, J., Jiang, Z., Hayashi, H., & Neubig, G. (2023). Pre-train, prompt, and predict: A systematic survey of prompting methods in natural language processing. ACM computing surveys, 55(9), 1-35.
[17] Marvin, G., Hellen, N., Jjingo, D., & Nakatumba-Nabende, J. (2023, June). Prompt engineering in large language models. In International Conference on Data Intelligence and Cognitive Informatics (pp. 387-402). Singapore: Springer Nature Singapore.
[18] Srivastava, S., Huang, C., Fan, W., & Yao, Z. (2023). Instances need more care: Rewriting prompts for instances with LLMs in the loop yields better zero-shot performance. arXiv preprint arXiv:2310.02107.
[19] Zhou, Y., Muresanu, A. I., Han, Z., Paster, K., Pitis, S., Chan, H., & Ba, J. (2022, November). Large language models are human-level prompt engineers in the Eleventh International Conference on Learning Representations.
[20] Welch, C. (2006). Item and prompt development in performance testing. Handbook of test development, 303-327.
[21] House, R., Watt, A., & Williams, J. M. (2010, July). The genre of the performance evaluation: Prompts for eliciting effective feedback. In 2010 IEEE International Professional Communication Conference (pp. 281-288). IEEE.
[22] Rusum, G. P., Pappula, K. K., & Anasuri, S. (2020). Constraint Solving at Scale: Optimizing Performance in Complex Parametric Assemblies. International Journal of Emerging Trends in Computer Science and Information Technology, 1(2), 47-55. https://doi.org/10.63282/3050-9246.IJETCSIT-V1I2P106
[23] Pappula, K. K., & Anasuri, S. (2020). A Domain-Specific Language for Automating Feature-Based Part Creation in Parametric CAD. International Journal of Emerging Research in Engineering and Technology, 1(3), 35-44. https://doi.org/10.63282/3050-922X.IJERET-V1I3P105
[24] Rahul, N. (2020). Optimizing Claims Reserves and Payments with AI: Predictive Models for Financial Accuracy. International Journal of Emerging Trends in Computer Science and Information Technology, 1(3), 46-55. https://doi.org/10.63282/3050-9246.IJETCSIT-V1I3P106
[25] Enjam, G. R. (2020). Ransomware Resilience and Recovery Planning for Insurance Infrastructure. International Journal of AI, BigData, Computational and Management Studies, 1(4), 29-37. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V1I4P104
[26] Pappula, K. K., Anasuri, S., & Rusum, G. P. (2021). Building Observability into Full-Stack Systems: Metrics That Matter. International Journal of Emerging Research in Engineering and Technology, 2(4), 48-58. https://doi.org/10.63282/3050-922X.IJERET-V2I4P106
[27] Pedda Muntala, P. S. R., & Karri, N. (2021). Leveraging Oracle Fusion ERP’s Embedded AI for Predictive Financial Forecasting. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 2(3), 74-82. https://doi.org/10.63282/3050-9262.IJAIDSML-V2I3P108
[28] Rahul, N. (2021). Strengthening Fraud Prevention with AI in P&C Insurance: Enhancing Cyber Resilience. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 2(1), 43-53. https://doi.org/10.63282/3050-9262.IJAIDSML-V2I1P106
[29] Enjam, G. R. (2021). Data Privacy & Encryption Practices in Cloud-Based Guidewire Deployments. International Journal of AI, BigData, Computational and Management Studies, 2(3), 64-73. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V2I3P108
[30] Rusum, G. P. (2022). WebAssembly across Platforms: Running Native Apps in the Browser, Cloud, and Edge. International Journal of Emerging Trends in Computer Science and Information Technology, 3(1), 107-115. https://doi.org/10.63282/3050-9246.IJETCSIT-V3I1P112
[31] Pappula, K. K. (2022). Architectural Evolution: Transitioning from Monoliths to Service-Oriented Systems. International Journal of Emerging Research in Engineering and Technology, 3(4), 53-62. https://doi.org/10.63282/3050-922X.IJERET-V3I4P107
[32] Jangam, S. K. (2022). Self-Healing Autonomous Software Code Development. International Journal of Emerging Trends in Computer Science and Information Technology, 3(4), 42-52. https://doi.org/10.63282/3050-9246.IJETCSIT-V3I4P105
[33] Pedda Muntala, P. S. R. (2022). Anomaly Detection in Expense Management using Oracle AI Services. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 3(1), 87-94. https://doi.org/10.63282/3050-9262.IJAIDSML-V3I1P109
[34] Rahul, N. (2022). Automating Claims, Policy, and Billing with AI in Guidewire: Streamlining Insurance Operations. International Journal of Emerging Research in Engineering and Technology, 3(4), 75-83. https://doi.org/10.63282/3050-922X.IJERET-V3I4P109
[35] Enjam, G. R. (2022). Energy-Efficient Load Balancing in Distributed Insurance Systems Using AI-Optimized Switching Techniques. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 3(4), 68-76. https://doi.org/10.63282/3050-9262.IJAIDSML-V3I4P108
[36] Rusum, G. P., & Anasuri, S. (2023). Composable Enterprise Architecture: A New Paradigm for Modular Software Design. International Journal of Emerging Research in Engineering and Technology, 4(1), 99-111. https://doi.org/10.63282/3050-922X.IJERET-V4I1P111
[37] Pappula, K. K. (2023). Reinforcement Learning for Intelligent Batching in Production Pipelines. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 4(4), 76-86. https://doi.org/10.63282/3050-9262.IJAIDSML-V4I4P109
[38] Jangam, S. K., & Pedda Muntala, P. S. R. (2023). Challenges and Solutions for Managing Errors in Distributed Batch Processing Systems and Data Pipelines. International Journal of Emerging Research in Engineering and Technology, 4(4), 65-79. https://doi.org/10.63282/3050-922X.IJERET-V4I4P107
[39] Pedda Muntala, P. S. R., & Karri, N. (2023). Leveraging Oracle Digital Assistant (ODA) to Automate ERP Transactions and Improve User Productivity. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 4(4), 97-104. https://doi.org/10.63282/3050-9262.IJAIDSML-V4I4P111
[40] Rahul, N. (2023). Transforming Underwriting with AI: Evolving Risk Assessment and Policy Pricing in P&C Insurance. International Journal of AI, BigData, Computational and Management Studies, 4(3), 92-101. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V4I3P110
[41] Enjam, G. R. (2023). Modernizing Legacy Insurance Systems with Microservices on Guidewire Cloud Platform. International Journal of Emerging Research in Engineering and Technology, 4(4), 90-100. https://doi.org/10.63282/3050-922X.IJERET-V4I4P109
[42] Pappula, K. K., & Rusum, G. P. (2020). Custom CAD Plugin Architecture for Enforcing Industry-Specific Design Standards. International Journal of AI, BigData, Computational and Management Studies, 1(4), 19-28. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V1I4P103
[43] Rahul, N. (2020). Vehicle and Property Loss Assessment with AI: Automating Damage Estimations in Claims. International Journal of Emerging Research in Engineering and Technology, 1(4), 38-46. https://doi.org/10.63282/3050-922X.IJERET-V1I4P105
[44] Enjam, G. R., & Tekale, K. M. (2020). Transitioning from Monolith to Microservices in Policy Administration. International Journal of Emerging Research in Engineering and Technology, 1(3), 45-52. https://doi.org/10.63282/3050-922X.IJERETV1I3P106
[45] Pappula, K. K., & Rusum, G. P. (2021). Designing Developer-Centric Internal APIs for Rapid Full-Stack Development. International Journal of AI, BigData, Computational and Management Studies, 2(4), 80-88. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V2I4P108
[46] Pedda Muntala, P. S. R., & Jangam, S. K. (2021). End-to-End Hyperautomation with Oracle ERP and Oracle Integration Cloud. International Journal of Emerging Research in Engineering and Technology, 2(4), 59-67. https://doi.org/10.63282/3050-922X.IJERET-V2I4P107
[47] Rahul, N. (2021). AI-Enhanced API Integrations: Advancing Guidewire Ecosystems with Real-Time Data. International Journal of Emerging Research in Engineering and Technology, 2(1), 57-66. https://doi.org/10.63282/3050-922X.IJERET-V2I1P107
[48] Enjam, G. R., & Chandragowda, S. C. (2021). RESTful API Design for Modular Insurance Platforms. International Journal of Emerging Research in Engineering and Technology, 2(3), 71-78. https://doi.org/10.63282/3050-922X.IJERET-V2I3P108
[49] Rusum, G. P., & Pappula, kiran K. . (2022). Event-Driven Architecture Patterns for Real-Time, Reactive Systems. International Journal of Emerging Research in Engineering and Technology, 3(3), 108-116. https://doi.org/10.63282/3050-922X.IJERET-V3I3P111
[50] Pappula, K. K. (2022). Containerized Zero-Downtime Deployments in Full-Stack Systems. International Journal of AI, BigData, Computational and Management Studies, 3(4), 60-69. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V3I4P107
[51] Jangam, S. K. (2022). Role of AI and ML in Enhancing Self-Healing Capabilities, Including Predictive Analysis and Automated Recovery. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 3(4), 47-56. https://doi.org/10.63282/3050-9262.IJAIDSML-V3I4P106
[52] Pedda Muntala, P. S. R. (2022). Natural Language Querying in Oracle Fusion Analytics: A Step toward Conversational BI. International Journal of Emerging Trends in Computer Science and Information Technology, 3(3), 81-89. https://doi.org/10.63282/3050-9246.IJETCSIT-V3I3P109
[53] Rahul, N. (2022). Optimizing Rating Engines through AI and Machine Learning: Revolutionizing Pricing Precision. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 3(3), 93-101. https://doi.org/10.63282/3050-9262.IJAIDSML-V3I3P110
[54] Enjam, G. R. (2022). Secure Data Masking Strategies for Cloud-Native Insurance Systems. International Journal of Emerging Trends in Computer Science and Information Technology, 3(2), 87-94. https://doi.org/10.63282/3050-9246.IJETCSIT-V3I2P109
[55] Rusum, G. P., & Anasuri, S. (2023). Synthetic Test Data Generation Using Generative Models. International Journal of Emerging Trends in Computer Science and Information Technology, 4(4), 96-108. https://doi.org/10.63282/3050-9246.IJETCSIT-V4I4P111
[56] Pappula, K. K. (2023). Edge-Deployed Computer Vision for Real-Time Defect Detection. International Journal of AI, BigData, Computational and Management Studies, 4(3), 72-81. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V4I3P108
[57] Jangam, S. K. (2023). Data Architecture Models for Enterprise Applications and Their Implications for Data Integration and Analytics. International Journal of Emerging Trends in Computer Science and Information Technology, 4(3), 91-100. https://doi.org/10.63282/3050-9246.IJETCSIT-V4I3P110
[58] Pedda Muntala, P. S. R., & Karri, N. (2023). Managing Machine Learning Lifecycle in Oracle Cloud Infrastructure for ERP-Related Use Cases. International Journal of Emerging Research in Engineering and Technology, 4(3), 87-97. https://doi.org/10.63282/3050-922X.IJERET-V4I3P110
[59] Rahul, N. (2023). Personalizing Policies with AI: Improving Customer Experience and Risk Assessment. International Journal of Emerging Trends in Computer Science and Information Technology, 4(1), 85-94. https://doi.org/10.63282/3050-9246.IJETCSIT-V4I1P110
[60] Enjam, G. R., Tekale, K. M., & Chandragowda, S. C. (2023). Zero-Downtime CI/CD Production Deployments for Insurance SaaS Using Blue/Green Deployments. International Journal of Emerging Research in Engineering and Technology, 4(3), 98-106. https://doi.org/10.63282/3050-922X.IJERET-V4I3P111
[61] Pappula, K. K. (2020). Browser-Based Parametric Modeling: Bridging Web Technologies with CAD Kernels. International Journal of Emerging Trends in Computer Science and Information Technology, 1(3), 56-67. https://doi.org/10.63282/3050-9246.IJETCSIT-V1I3P107
[62] Enjam, G. R., & Tekale, K. M. (2020). Transitioning from Monolith to Microservices in Policy Administration. International Journal of Emerging Research in Engineering and Technology, 1(3), 45-52. https://doi.org/10.63282/3050-922X.IJERETV1I3P106
[63] Pappula, K. K. (2021). Modern CI/CD in Full-Stack Environments: Lessons from Source Control Migrations. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 2(4), 51-59. https://doi.org/10.63282/3050-9262.IJAIDSML-V2I4P106
[64] Pedda Muntala, P. S. R. (2021). Prescriptive AI in Procurement: Using Oracle AI to Recommend Optimal Supplier Decisions. International Journal of AI, BigData, Computational and Management Studies, 2(1), 76-87. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V2I1P108
[65] Enjam, G. R., Chandragowda, S. C., & Tekale, K. M. (2021). Loss Ratio Optimization using Data-Driven Portfolio Segmentation. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 2(1), 54-62. https://doi.org/10.63282/3050-9262.IJAIDSML-V2I1P107
[66] Rusum, G. P., & Pappula, K. K. (2022). Federated Learning in Practice: Building Collaborative Models While Preserving Privacy. International Journal of Emerging Research in Engineering and Technology, 3(2), 79-88. https://doi.org/10.63282/3050-922X.IJERET-V3I2P109
[67] Pappula, K. K. (2022). Modular Monoliths in Practice: A Middle Ground for Growing Product Teams. International Journal of Emerging Trends in Computer Science and Information Technology, 3(4), 53-63. https://doi.org/10.63282/3050-9246.IJETCSIT-V3I4P106
[68] Jangam, S. K., Karri, N., & Pedda Muntala, P. S. R. (2022). Advanced API Security Techniques and Service Management. International Journal of Emerging Research in Engineering and Technology, 3(4), 63-74. https://doi.org/10.63282/3050-922X.IJERET-V3I4P108
[69] Pedda Muntala, P. S. R. (2022). Detecting and Preventing Fraud in Oracle Cloud ERP Financials with Machine Learning. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 3(4), 57-67. https://doi.org/10.63282/3050-9262.IJAIDSML-V3I4P107
[70] Rahul, N. (2022). Enhancing Claims Processing with AI: Boosting Operational Efficiency in P&C Insurance. International Journal of Emerging Trends in Computer Science and Information Technology, 3(4), 77-86. https://doi.org/10.63282/3050-9246.IJETCSIT-V3I4P108
[71] Enjam, G. R., & Tekale, K. M. (2022). Predictive Analytics for Claims Lifecycle Optimization in Cloud-Native Platforms. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 3(1), 95-104. https://doi.org/10.63282/3050-9262.IJAIDSML-V3I1P110
[72] Rusum, G. P., & Pappula, K. K. (2023). Low-Code and No-Code Evolution: Empowering Domain Experts with Declarative AI Interfaces. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 4(2), 105-112. https://doi.org/10.63282/3050-9262.IJAIDSML-V4I2P112
[73] Pappula, K. K., & Rusum, G. P. (2023). Multi-Modal AI for Structured Data Extraction from Documents. International Journal of Emerging Research in Engineering and Technology, 4(3), 75-86. https://doi.org/10.63282/3050-922X.IJERET-V4I3P109
[74] Jangam, S. K., Karri, N., & Pedda Muntala, P. S. R. (2023). Develop and Adapt a Salesforce User Experience Design Strategy that Aligns with Business Objectives. International Journal of Emerging Trends in Computer Science and Information Technology, 4(1), 53-61. https://doi.org/10.63282/3050-9246.IJETCSIT-V4I1P107
[75] Pedda Muntala, P. S. R., & Jangam, S. K. (2023). Context-Aware AI Assistants in Oracle Fusion ERP for Real-Time Decision Support. International Journal of Emerging Trends in Computer Science and Information Technology, 4(1), 75-84. https://doi.org/10.63282/3050-9246.IJETCSIT-V4I1P109
[76] Enjam, G. R. (2023). AI Governance in Regulated Cloud-Native Insurance Platforms. International Journal of AI, BigData, Computational and Management Studies, 4(3), 102-111. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V4I3P111
[77] Rusum, G. P. (2023). Secure Software Supply Chains: Managing Dependencies in an AI-Augmented Dev World. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 4(3), 85-97. https://doi.org/10.63282/3050-9262.IJAIDSML-V4I3P110
[78] Enjam, G. R. (2020). Ransomware Resilience and Recovery Planning for Insurance Infrastructure. International Journal of AI, BigData, Computational and Management Studies, 1(4), 29-37. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V1I4P104
[79] Pappula, K. K., & Anasuri, S. (2021). API Composition at Scale: GraphQL Federation vs. REST Aggregation. International Journal of Emerging Trends in Computer Science and Information Technology, 2(2), 54-64. https://doi.org/10.63282/3050-9246.IJETCSIT-V2I2P107
[80] Pedda Muntala, P. S. R. (2021). Integrating AI with Oracle Fusion ERP for Autonomous Financial Close. International Journal of AI, BigData, Computational and Management Studies, 2(2), 76-86. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V2I2P109
[81] Rusum, G. P. (2022). Security-as-Code: Embedding Policy-Driven Security in CI/CD Workflows. International Journal of AI, BigData, Computational and Management Studies, 3(2), 81-88. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V3I2P108
[82] Jangam, S. K., & Pedda Muntala, P. S. R. (2022). Role of Artificial Intelligence and Machine Learning in IoT Device Security. International Journal of Artificial Intelligence, Data Science, and Machine Learning, 3(1), 77-86. https://doi.org/10.63282/3050-9262.IJAIDSML-V3I1P108
[83] Pedda Muntala, P. S. R. (2022). Enhancing Financial Close with ML: Oracle Fusion Cloud Financials Case Study. International Journal of AI, BigData, Computational and Management Studies, 3(3), 62-69. https://doi.org/10.63282/3050-9416.IJAIBDCMS-V3I3P108