@@ -172,6 +172,8 @@ type OpenRouterResponse = {
172172export class SignatureLLM implements ExtractSignature {
173173 LLM_ENDPOINT = 'https://openrouter.ai/api/v1/chat/completions' ;
174174
175+ MAX_OUTPUT_TOKENS = 1000 ;
176+
175177 private active = true ;
176178
177179 constructor (
@@ -210,13 +212,17 @@ export class SignatureLLM implements ExtractSignature {
210212 content : SignaturePrompt . buildUserPrompt ( email , signature )
211213 }
212214 ] ,
213- response_format : SignaturePrompt . response_format
215+ response_format : SignaturePrompt . response_format ,
216+ max_tokens : this . MAX_OUTPUT_TOKENS
214217 } ) ;
215218 }
216219
217220 private handleResponseError ( error : OpenRouterError [ 'error' ] ) {
218221 if ( [ 402 , 502 , 503 ] . includes ( error . code ) ) {
219222 this . active = false ;
223+ this . logger . warn (
224+ 'LLM engine down — check credits balance or expired/invalid API token'
225+ ) ;
220226 }
221227 throw new Error ( error . message ) ;
222228 }
@@ -279,9 +285,15 @@ export class SignatureLLM implements ExtractSignature {
279285 try {
280286 const content = await this . sendPrompt ( email , signature ) ;
281287
282- this . logger . debug ( `extract signature content: ${ content } ` ) ;
288+ if ( ! content || content . toLowerCase ( ) === 'null' ) {
289+ this . logger . debug ( 'Received empty or null response. skipping parse' ) ;
290+ return null ;
291+ }
283292
284- if ( ! content || content . toLowerCase ( ) === 'null' ) return null ;
293+ if ( content . length > this . MAX_OUTPUT_TOKENS ) {
294+ this . logger . debug ( 'Model response was too large, skipping parse' ) ;
295+ return null ;
296+ }
285297
286298 const parsed = JSON . parse ( content ) ;
287299 const person = Array . isArray ( parsed ) ? parsed [ 0 ] : parsed ;
0 commit comments