A DSPy adapter that attempts progressively more lenient parsing strategies when strict JSON parsing fails. Falls back to empty default values if all parsing strategies fail.
Parameters
Name
Type
Description
Default
return_defaults_on_failure
bool
If True, returns default empty values when all parsing strategies fail. If False, raises the original parsing error.
True
trace
bool
If True, prints debug information during parsing attempts.
False
Returns
Name
Type
Description
LocalChatAdapter
An object of type LocalChatAdapter, extending ChatAdapter
Examples
>>>import dspy>>>from llama_cpp import Llama>>>from localllm import LocalLLM, localllm_download_model, LocalChatAdapter>>> path = localllm_download_model("gemma-3-270m-it-Q8_0", trace =False)>>> transformer = Llama(model_path=path, n_gpu_layers=-1, flash_attn =False, n_ctx =32768, n_threads =1, seed =4321, verbose =False)>>> dspy.configure(lm = LocalLLM(transformer, trace =False), adapter = LocalChatAdapter(return_defaults_on_failure =True, trace =False))>>>class Go(dspy.Signature):... sentence: str= dspy.InputField(desc ="A question")... answer: str= dspy.OutputField(desc="A city name")>>>>>> model = dspy.Predict(Go)>>> out = model(sentence="What city is the Capital of Belgium")