# Data Imputation Based on Retrieval-Augmented Generation
## 3 Methods
### Inference Optimization Methods Under Cost Constraints
For example, compared to a simple prompt like \"fill in the missing sales data\", a prompt that includes an additional reasoning process--\"Approach: First, analyze the pattern of the missing data, then use the sales trends of similar periods to impute, and finally verify the consistency of the imputed data with the overall sales trend\"--typically generates higher-quality code, as this reasoning provides the LLMs with valuable guidance on how to solve the problem. **Validated Code Generation. ** In this study, rather than relying on users to manually write down their suggestions, we introduce a separate LLM dialogue to automatically generate recommendations. As shown in Figure 4, the validated code generation method comprises three key components: an LLM advisor, LLM code generator, and verifier. The LLM advisor communicates with the LLM code generator and verifier, providing suggestions for generating code snippets based on the task. The verifier automatically checks the semantic and logical correctness of the generated code. The code and error messages are then relayed back to the LLM advisor based on the verification results, repeating this process until the code passes all test cases or times out. Through such iterative processes, the LLMs can produce more robust and resilient code snippets. **Evolutionary Code Integration. ** For tasks requiring intricate logic and multiple combinatorial rules, evolutionary code integration generates a diverse set of complementary code snippets. As shown in Figure 5, these snippets undergo iterative optimization, where less effective code is discarded and successful code snippets are combined to handle complex scenarios. This evolutionary approach ensures that the final codebase is both robust and capable of handling the multifaceted requirements of data imputation tasks. Since theoretically verifying the correctness of LLM-generated code remains an open issue, this study explores empirical validation methods to comprehensively verify code and minimize potential errors. Two methods are introduced: logical correctness assessment and example generation. Both aim to minimize user involvement and the required testing samples. Note that the code verification process proposed in this study is flexible and can  
Figure 4: Code framework. support any validation method, as long as it returns the verification result in the form of <result, error information>. Logical Correctness Assessment: Given that LLMs can understand natural language requirements and code logic, they can be directly asked to assess the logical correctness of the generated code and its alignment with the task requirements. Specifically, similar to the verifier in the code generation process, the LLM is provided with complete profile information: the code to be verified, the program runtime environment, etc. The LLM is explicitly asked to provide judgments and reasoning processes, which are then used as evidence. However, since this type of validation heavily relies on the performance of the LLM, it is typically less reliable. Therefore, this study allows the LLM advisor to discard suspicious verification results using the SKIP CASE method. Logical correctness assessment is the most fundamental and general solution for using LLMs in code validation. Example (test case) Generation: Human programmers typically rely on test cases to check their code. When test cases are available, the generated code is placed in a sandbox and tested against all examples. A result of result=1 is returned only when the generated code passes all test cases, requiring no evidence. Failure on any test case, including compilation errors, format errors, timeouts, or incorrect outputs, is marked as result=0, with errors returned as evidence. In many cases, users do not provide sufficient test examples. Therefore, it is necessary to use LLMs to automatically generate examples as test cases.