Skip to content

Exception messages raised in input_fn are not shown after invoke_endpoint raises an error #2067

Closed

Description

@MichalShuviPowtoon

Hi,
I'm using SKLearn estimator and my inference script contains something like:

def predict_fn(input_data, model):
    a = input_data.get('a')
    if asset_type and type(a) != str:
        raise Exception(f'The asset type must be a string, not {type(asset_type).__name__}')

after running the following code with a false body, e.g. a = [a, b, c]:

client = boto3.client('sagemaker-runtime')
try:
    response = client.invoke_endpoint(
           EndpointName=endpoint_name, 
           Body=body, 
           ContentType='application/json')
except client.exceptions.ModelError as e:
  print(e.response)

I get:
{'Error': {'Message': 'Received server error (500) from model with message "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n"..... }

Why can't I see my exception message in the output as written in input_fn? (in the cloudWatch console it is shown)

Thank you

Activity

  1. changed the title [-]Exception messages raised in input_fn are not shown after invoke_endpoint raises error[/-] [+]Exception messages raised in input_fn are not shown after invoke_endpoint raises an error[/+] on Jan 5, 2021
  2. ajaykarpur commented on Jan 5, 2021

    @ajaykarpur
    Contributor

    It looks like you're using boto3, not the SageMaker Python SDK. Here is relevant documentation for the SageMaker Python SDK: https://sagemaker.readthedocs.io/en/stable/frameworks/sklearn/sagemaker.sklearn.html

    You can install the SDK with pip install sagemaker.

  3. MichalShuviPowtoon commented on Jan 6, 2021

    @MichalShuviPowtoon
    Author

    Thank you for the quick response, I tried also the SKLearn predictor from the SDK:

    from sagemaker.sklearn.model import SKLearnPredictor
    input_data = {'a': [8108]} # not a string as required
    try:
        predictor = SKLearnPredictor(endpoint_name=endpoint_name,  serializer=sagemaker.serializers.JSONSerializer('application/json'))
        inference_response = predictor.predict(data=input_data)
        print(inference_response)
    except client.exceptions.ModelError as e:
      print(e.response)
    

    but I still get the same non-informative error:

    {'Error': {'Message': 'Received server error (500) from model with message
    "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<p>The server encountered an internal error and was unable to complete your request...}
    
  4. ahsan-z-khan commented on Sep 30, 2021

    @ahsan-z-khan
    Contributor

    Hi @MichalShuviPowtoon, please reopen if the issue still persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions