Skip to content

Commit 8f082ce

Browse files
committed
do a real check
1 parent 12d0bb7 commit 8f082ce

File tree

1 file changed

+10
-3
lines changed
  • js/packages/openinference-instrumentation-langchain/src

1 file changed

+10
-3
lines changed

js/packages/openinference-instrumentation-langchain/src/utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,19 @@ function formatPromptTemplate(run: Run): PromptTemplateAttributes | null {
497497
function getTokenCount(maybeCount: unknown) {
498498
return isNumber(maybeCount) ? maybeCount : undefined;
499499
}
500+
500501
/**
501-
* A simple function that determines if a string is JSON like
502-
* Note this is a rough check just to set the MIME type
502+
* A function that determines if a string is JSON like
503+
* @param str - The string to check
504+
* @returns true if the string is JSON
503505
*/
504506
function isJSONString(str: string) {
505-
return str.startsWith("{") && str.endsWith("}");
507+
try {
508+
JSON.parse(str);
509+
return true;
510+
} catch {
511+
return false;
512+
}
506513
}
507514

508515
/**

0 commit comments

Comments
 (0)