Failure and then success in querying an LLM
I enjoy accelerating my software development with the help of LLMs. However, this extra LLM based support does not always work. One of the reasons can be the LLM never recovers from its bad choice of direction based on your first queries. Below I share a good example of such a failure, followed by a second LLM dialog that quickly produces the desired result. Then I explain what is happening.
Here is the dialog that fails, I am trying to get the LLM to produce a draft differentiation approximation based on wavelets, and coded in JAX:
- Me: Do some wavelets have special properties with regards to derivatives? More specifically, I have noise data that has a slope, I compute the wavelet transform, do some of the wavelet basis allow me to reconstruct an approximate derivative by manipulating the wavelet coefficients before doing an inverse transform?
- (To note that I naturally try not to impose my knowledge, and therefore why I tend to carefully introduce new knowledge (with people, obviously with LLMs too). The point being that I have used wavelets to extract derivatives in the past, yet many years of collaboration has taught me that one gets better result when others have the opportunity to drive the conversation).
- LLM: Produces positive answer with some theory.
- Me: can you write a jax example unsing cr-wavelets and computing approximate derivatives?
- LLM: Produces code that is based on pywt.
- Me: Not pywt, I meant CR-Sparse / CR-Wavelets
- LLM: Still produces code based on pywt.
- Me: You previously wrote: "CR-Sparse / CR-Wavelets: This library includes a module for wavelet transforms (both DWT and CWT) built on top of JAX. It mentions being a partial port of PyWavelets functionality, rewritten in pure Python using the JAX API to leverage XLA for acceleration on GPUs/TPUs. It provides both high-level (flexible but not always JIT-compilable) and low-level (JIT-compilable) functions". Therefore we do not want pywt, we want to use cr.wavelets
- LLM: produces code that starts by initializing a cr.wavelets based solution, but then proceeds to "Get Wavelet Filter Coefficients (using PyWavelets for reliability)" <- the LLM's explanation. And of course PyWavelets is part of pywt which is not what I want.
- Me: ouch, I give up on you. (and some further ranting!)
- LLM: I sincerely apologize for the confusion and frustration my responses have caused....There is absolutely no hidden agenda or instruction to avoid any particular library like CR-Sparse
- Me: Can you tell me what type of features are implemented in the cr-wavelets jax based library?
- LLM: Tells me about cr-wavelets.
- Me: Great. Can you help me implement in jax a wavelet based computation of the approximate slopes (derivatives) of some one dimensional data? How about we use the sym4 basis?
- LLM: Produces the proper JAX code (with a minor typo).
- In the first chat, when I first mentioned cr-wavelets, the LLM knew that cr-wavelets is tied to cr-sparse but not that it contained wavelet implementations, and knew that one could implement wavelets by fully implementing them in cr-sparse, but also knew that that is expensive, especially knowing the pywt has wavelets, so even while later in the dialog the LLM has "loaded" the knowledge of what cr-wavelets does, it really had a hard time stepping away from the initial finding that using cr-wavelets was going to be too expensive.
- In the second dialog, I purposely pushed the LLM to "load" the knowledge of what cr-wavelets could do. Then I made the request to use cr-wavelets. Which worked well.
Choose very carefully your first choice of inputs when interacting with an LLM!
In the case of using the LLM as a coding assistant, it is very important that the LLM fully understands the resources you intend to use before you ask any form question that may concern these resources.
All original content copyright James Litsios, 2025.