Detection and correction of inaccurate numeric comparisons in LLM responses
Systems, methods, and other embodiments are described herein which are associated with detection and correction of large language model responses in natural language that contain inaccurate numeric comparisons. In one embodiment, a method includes intercepting an initial response by a large language model to an initial prompt. The method includes detecting that the initial response contains an inaccuracy in a numeric comparison based on a validation check of the numeric comparison. The method includes generating an alternative prompt to the large language model that is configured to cause the large language model to correct the inaccuracy in a rectified response. And, the method includes returning the rectified response by the large language model to the alternative prompt in place of the initial response.
1 . One or more non-transitory computer-readable media that include stored thereon computer-executable instructions that when executed by at least a processor of a computing system cause the computing system to:
intercept, from an endpoint of a large language model, an original response by the large language model to an original prompt from a client system, wherein the original response is withheld from being returned to the client system and is redirected into an issue identification analysis, wherein the original response is in natural language;
detect, by the issue identification analysis, that the original response contains an inaccuracy in a numeric comparison by: (i) automatically constructing a mathematical expression from a first number, a second number, and a relationship described in the numeric comparison, and (ii) evaluating the mathematical expression to determine that the numeric comparison fails a validation check;
automatically generate an alternative prompt to the large language model that is configured to cause the large language model to correct the inaccuracy in a rectified response; and
return, to the client system, the rectified response by the large language model to the alternative prompt in place of the original response, without returning the original response to the client system, wherein the rectified response is in natural language.
2 . The one or more non-transitory computer-readable media of claim 1 , wherein the instructions for automatically constructing the mathematical expression further cause the computing system to extract the first number, the second number, and the relationship from the natural language of the original response using an additional prompt.
3 . The one or more non-transitory computer-readable media of claim 1 , wherein the instructions for detecting that the original response contains the inaccuracy in the numeric comparison further cause the computing system to:
detect language that indicates the numeric comparison in the original response;
based on comparative language in the original response, classify the relationship between the first number and the second number as one of (i) higher than, (ii) equal to, (iii) lower than, (iv) percentage of, (v) fraction of, or (vi) multiple of;
submit to the large language model an additional prompt that corresponds to the relationship, wherein the additional prompt is configured to cause the large language model to extract the first number and the second number from the original response;
populate a logical statement with the first number, the relationship, and the second number to automatically construct the mathematical expression; and
evaluate the logical statement to determine that the numeric comparison fails the validation check because the logical statement evaluates to false.
4 . The one or more non-transitory computer-readable media of claim 1 , wherein the instructions for detecting that the original response contains the inaccuracy in the numeric comparison further cause the computing system to:
detect that the original response includes a difference value between the first number and the second number;
submit to the large language model an additional prompt that is configured to cause the large language model to extract the difference value from the original response;
populate an equation with the first number, the second number, and the difference value to automatically construct the mathematical expression; and
evaluate the equation to determine that the numeric comparison fails the validation check because the difference value is incorrect.
5 . The one or more non-transitory computer-readable media of claim 1 , wherein the instructions further cause the computing system to, prior to detection of the inaccuracy in the numeric comparison:
access structured data that is included in the original prompt to the large language model;
extract source numerical data from the structured data and generated numerical data from the original response; and
verify the generated numerical data against the source numerical data.
6 . The one or more non-transitory computer-readable media of claim 1 , further comprising instructions that when executed by at least the processor cause the computing system to repeat the intercepting of the original response, the detecting that the original response contains the inaccuracy, the generating the alternative prompt, and the returning the rectified response until either: (A) no further inaccuracy is detected, or (B) a threshold for number of iterations is satisfied, wherein the original response for an iteration is the rectified response for a prior iteration.
7 . The one or more non-transitory computer-readable media of claim 6 , further comprising instructions that when executed by at least the processor cause the computing system to, during the generating the alternative prompt, rotate through a plurality of prompt strategies, wherein the plurality of prompt strategies includes: (i) a first prompt strategy of passing error information about the inaccuracy and suggested rectification to the large language model as context; and (ii) a second prompt strategy of responding to the original prompt with adjusted settings applied to one or more inference parameters.
8 . A computer-implemented method, comprising:
intercepting an initial response by a large language model to an initial prompt from a client system, wherein the original response is withheld from being returned to the client system and is redirected into an issue identification analysis;
detecting, by the issue identification analysis, that the initial response contains an inaccuracy in a numeric comparison by: (i) automatically constructing a mathematical expression from a first number, a second number, and a relationship described in the numeric comparison, and (ii) evaluating the mathematical expression to determine that the numeric comparison fails a validation check;
dynamically assembling an alternative prompt to the large language model that is configured to cause the large language model to correct the inaccuracy in a rectified response; and
returning, to the client system, the rectified response by the large language model to the alternative prompt in place of the initial response, without returning the original response to the client system.
9 . The computer-implemented method of claim 8 , wherein detecting that the initial response contains the inaccuracy in the numeric comparison further comprises:
populating a logical statement of the relationship between the first number and the second number to automatically construct the mathematical expression; and
evaluating the logical statement to determine that the numeric comparison fails the validation check because the logical statement evaluates to false.
10 . The computer-implemented method of claim 8 , wherein detecting that the initial response contains the inaccuracy in the numeric comparison further comprises:
detecting a difference value in the initial response;
populating a mathematical statement that subtracts the second number from the first number to produce the difference value to automatically construct the mathematical expression; and
evaluating the mathematical statement to determine that the numeric comparison fails the validation check because subtracting the second number from the first number does not equal the difference value, to detect the inaccuracy.
11 . The computer-implemented method of claim 8 , further comprising verifying that numerical data from the initial response also appear in structured data provided in the initial prompt.
12 . The computer-implemented method of claim 8 , wherein the intercepting, detecting, and generating steps of the computer-implemented method iterate upon generation of the rectified response until either: (A) no further inaccuracy is detected, or (B) a cap on iterations is reached, wherein the initial response for an iteration is the rectified response for a prior iteration, the computer-implemented method further comprising changing prompt strategies from iteration to iteration.
13 . The computer-implemented method of claim 8 , further comprising generating the rectified response where a reference text for the numeric comparison is unavailable.
14 . A computing system, comprising:
at least one processor connected to at least one memory;
one or more non-transitory computer-readable media that include stored thereon computer-executable instructions that when executed by at least a processor of the computing system cause the computing system to:
intercept an initial response by a large language model to an initial prompt by a client system before the initial response is returned to the client system and redirected to an issue identification analysis;
detect, by the issue identification analysis, that the initial response contains an inaccuracy in a numeric comparison by: (i) automatically constructing a mathematical expression from a first number, a second number, and a relationship described in the numeric comparison, and (ii) evaluating the mathematical expression to determine that the numeric comparison fails a validation check;
generate an alternative prompt to the large language model that is configured to cause the large language model to correct the inaccuracy in a rectified response; and
return, to the client system, the rectified response by the large language model to the alternative prompt as a replacement for the initial response.
15 . The computing system of claim 14 , wherein the instructions for detecting that the initial response contains the inaccuracy in the numeric comparison, when executed by at least the processor, further cause the computing system to detect that the numeric comparison fails the validation check because a logical statement of the relationship between the first number and the second number in the initial response is false.
16 . The computing system of claim 14 , wherein the instructions for detecting that the initial response contains the inaccuracy in the numeric comparison, when executed by at least the processor, further cause the computing system to detect that the numeric comparison fails the validation check because a mathematical statement to produce a difference value in the initial response by subtracting the second number from the first number is incorrect.
17 . The computing system of claim 14 , wherein the instructions, when executed by at least the processor, further cause the computing system to detect that there are one or more numbers in the initial response that are unverifiable from structured data used to create the initial prompt.
18 . The computing system of claim 14 , wherein the instructions for generating the alternative prompt to the large language model that is configured to cause the large language model to correct the inaccuracy in the rectified response, when executed by at least the processor, further cause the computing system to one or more of:
automatically determine an actual relationship between a pair of numbers compared in the numeric comparison; and
automatically determine an actual difference between the pair of numbers compared in the numeric comparison.
19 . The computing system of claim 14 , wherein the computer-executable instructions, when executed by at least the processor, cause the computing system to:
perform the interception, the detection, and the generation for newly-generated rectified responses until either:
(A) no further inaccuracy is detected, or
(B) a threshold for number of iterations is satisfied; and
during the generation, rotate through a plurality of prompt strategies from iteration to iteration.
20 . The computing system of claim 14 , wherein the computer-executable instructions, when executed by at least the processor, cause the computing system to present the rectified response in a natural language user interface to a structured database.