Replies: 2 comments
-
|
Great questions! Here's what you can do: 1. Retry on failures: from tenacity import retry, stop_after_attempt, retry_if_exception_type
@retry(
stop=stop_after_attempt(3),
retry=retry_if_exception_type(ValueError)
)
def extract_with_retry(extractor, text):
return extractor.extract(text)2. Skip failed batches: results = []
for batch in text_batches:
try:
result = extractor.extract(batch)
results.append(result)
except Exception as e:
logger.warning(f"Batch failed: {e}")
results.append(None) # or skip
continue
# Filter successful extractions
successful = [r for r in results if r is not None]3. Save incremental progress: for i, batch in enumerate(batches):
result = extractor.extract(batch)
with open(f"checkpoint_{i}.json", "w") as f:
json.dump(result, f)For Claude specifically: The Would love to see native checkpoint/resume support in LangExtract though! 🤙 |
Beta Was this translation helpful? Give feedback.
-
|
Dealing with malformed JSON or NoneType errors mid-pipeline is a common frustration when using high-reasoning models like Claude 4.5, especially when an unexpected "hallucination" in the output format breaks the schema validation in LangExtract. Example Logic for Custom Provider def call_model_with_retry(prompt, max_retries=3): "Skipping" and Partial Progress Recovery |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
BLUF: Is there a way to recover when a generative output is malformed?
I am currently experimenting with LangExtract using a custom Bedrock model provider with Claude 4.5 as the generative model (due to limitations of my environment, this is the only generative model/platform I can use). However, due to the very nature of generative models, sometimes (but often enough) we get malformed responses from the model. When such an error occurs, this causes the whole LangExtract pipeline to fail and lose all progress. For example
Extraction text must be a string, integer, or float. Found: <class 'NoneType'>. In one case, I had extraction passes set to 3, and on the final pass the error arose and I lost all previous progress/extractions - this seems like such a waste!In the case of errors:
Mahalo! 🤙
Beta Was this translation helpful? Give feedback.
All reactions